SELECT请求中的多表关系

时间:2015-04-20 13:42:17

标签: sql postgresql

我该怎么做:

SELECT *
FROM table1, table2, table3
WHERE table1.champs = table2.champs = table3.champs

没有任何重复"冠军"因为3个表中至少有一个应该有重复的行。

2 个答案:

答案 0 :(得分:3)

改为使用现代JOIN语法:

SELECT *
FROM table1
  JOIN table2 ON table1.champs = table2.champs 
  JOIN table3 ON table2.champs = table3.champs
使用SELECT DISTINCT删除

重复的。如果你的意思是" 没有任何重复的冠军"。

答案 1 :(得分:1)

关于表格相关字段的INNER JOIN

SELECT *
FROM table1 t1
INNER JOIN table2 t2 ON t1.champs = t2.champs 
INNER JOIN table3 t3 ON t2.champs = t3.champs