假设有4个表,就是这样
t1.id = t2.pid
和
t3.id = t4.pid
如何获取t1.val1 != t3.val1 AND t2.val2 != t4.val2
?
答案 0 :(得分:0)
您需要使用LEFT OUTER JOIN
从两个表中查找不匹配的记录。
SELECT *
FROM t1
INNER JOIN t2
ON t1.id = t2.pid
LEFT OUTER JOIN t3
ON t2.pid = t3.id
LEFT OUTER JOIN t4
ON t3.id = t4.pid
WHERE (t1.val1 IS NULL OR t3.val1 IS NULL)
AND (t2.val2 IS NULL OR t4.val2 IS NULL)
访问:http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html