2012-10-16 83 views
0

我想要考虑一个查询,该查询将在表中搜索跨2个字段的匹配值。检查2个字段的匹配值

例如,将tbl_id 202和tbl_id 203标识为tbl_row和tbl_col中的匹配值的查询是什么?

db screen shot

感谢

tatty27

回答

0
select distinct t1.tbl_id 
from 
    tbl as t1 
    inner join tbl as t2 
     on t1.tbl_row = t2.tbl_row 
     and t1.tbl_col = t2.tbl_col 
     and t1.tbl_id <> t2.tbl_id 
+0

这样做的窍门,谢谢 – tatty27

0
Select T1.tbl_id, T2.tbl_id 
FROM Table T1, Table T2 
WHERE T1.tbl_row = T2.tbl_row and T1.tbl_col = T2.tbl_col and T1.tbl_id <> T2.tbl_id 
1

这不是做最彻底的方法,因为它会在行数翻倍返回的,而是”我会告诉你这些蠢事。假设表名是tbl:

select t1。 ,t2。 from tbl t1,tbl t2 where t1.tbl_row = t2.tbl_row and t1.tbl_col = t2.tbl_col;