0

我试图找到一个mysql 表的所有列之间的交集。我正在尝试的是:

select * from table where 
  col1=col2 AND col1=Col3 AND col1=Col4 AND 
  col2=Col3 AND col2=Col4 AND col3=Col4;

我不认为这个查询工作正常。有人可以提出一种有效的方法。请注意所有列都来自一张表

4

1 回答 1

0

您需要将表的实例连接在一起。

select distinct * from (
  select t1.col1 'intersection' from table t1, table t2
  where t1.col1=t2.col2 or t1.col1=t2.col3 or t1.col1=t2.col4
  union select t3.col2 'intersection' from table t3, table t4
  where t3.col2=t4.col3 or t3.col2=t4.col4
  union select t5.col3 'intersection' from table t5, table t6
  where t5.col3=t6.col4
)

[编辑] 修改为包括不涉及 column1 的交叉点,并显示值而不是整个记录。

于 2012-05-01T06:54:30.790 回答