MySQL ALL 子句中的多列
MySQL multiple columns in ALL clause
为什么不允许执行以下操作?
SELECT Column_1
FROM Mytable
WHERE (Column_1, Column_2) >= ALL(SELECT Column_1,Column_2 FROM MYTABLE2)
但是可以做到
SELECT Column_1
FROM Mytable
WHERE (Column_1, Column_2) IN (SELECT Column_1,Column_2 FROM MYTABLE2)
假设这是您要编写的查询:
select col1 from t1 where (col1, col2) > all(select col1, col2 from t2);
这在 MySQL 中不起作用,并引发错误:
Operand should contain 1 column(s)
MySQL 虽然支持元组(不)相等,所以你可以用 not exists
:
来表达
select col1
from t1
where not exists (
select 1
from t2
where (t2.col1, t2.col2) > (t1.col1, t1.col2)
)
为什么不允许执行以下操作?
SELECT Column_1
FROM Mytable
WHERE (Column_1, Column_2) >= ALL(SELECT Column_1,Column_2 FROM MYTABLE2)
但是可以做到
SELECT Column_1
FROM Mytable
WHERE (Column_1, Column_2) IN (SELECT Column_1,Column_2 FROM MYTABLE2)
假设这是您要编写的查询:
select col1 from t1 where (col1, col2) > all(select col1, col2 from t2);
这在 MySQL 中不起作用,并引发错误:
Operand should contain 1 column(s)
MySQL 虽然支持元组(不)相等,所以你可以用 not exists
:
select col1
from t1
where not exists (
select 1
from t2
where (t2.col1, t2.col2) > (t1.col1, t1.col2)
)