Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择所有行在一行的两列中具有相同值的记录_Mysql - Fatal编程技术网

Mysql 选择所有行在一行的两列中具有相同值的记录

Mysql 选择所有行在一行的两列中具有相同值的记录,mysql,Mysql,这是我的样品台 Col1 Col2 A A B B A C B D C C 我希望能够选择不同的记录,其中Col1和Col2中的所有行都具有相同的值。所以我的答案应该是 Col1 Col2 A A B B C C 简单地说: select distinct * from t where col1 = col2; 如果两个col都有null,并且您也想得到该行: select distinct * from

这是我的样品台

Col1 Col2
A      A
B      B
A      C
B      D
C      C
我希望能够选择不同的记录,其中Col1和Col2中的所有行都具有相同的值。所以我的答案应该是

Col1 Col2
A       A
B       B
C       C
简单地说:

select distinct * from t where col1 = col2;
如果两个col都有
null
,并且您也想得到该行:

select distinct * from t where coalesce(col1, col2) is null or col1 = col2;

查询已写入您的请求中:

选择不同的记录,其中所有行在Col1和Col2中具有相同的值


独特的*是矛盾的
SELECT DISTINCT *
FROM tbl
WHERE Col1 = Col2