我有两张桌子。 “t1”和“t2”
每个列有4列,其中前3列应该相同。 “t1.col1 = t2.col1,t1.col2 = t2.col2,t1.col3 = t2.col3”
我的问题是“t2”中缺少行,如果“t2”中不存在,则如何从“t1”中仅提取缺失的行
示例:
Table1 Table 2
||one||two||three||four ||one||two||three||four
||1 ||1 ||1 ||text ||1 ||1 ||1 ||text
||1 ||1 ||2 ||text ||1 ||1 ||2 ||text
||1 ||1 ||3 ||text ||1 ||1 ||3 ||text
||1 ||1 ||4 ||text ||1 ||2 ||1 ||text
||1 ||2 ||1 ||text ||1 ||2 ||2 ||text
||1 ||2 ||2 ||text ||1 ||2 ||3 ||text
表2中的缺失的行是“1 || 1 || 4 || text”
我只需要从表1中检索所有缺失的行
提前感谢您的时间!
答案 0 :(得分:1)
试试这个:
SELECT *
FROM t1 AS A
LEFT JOIN t2 AS B ON A.one = B.one AND A.two = B.two AND A.three = B.three
WHERE B.four IS NULL
答案 1 :(得分:0)
SELECT col1, col2, col3, col4 FROM t1
WHERE (col1, col2, col3, col4) NOT IN
(SELECT col1, col2, col3, col4 FROM t2)
除了左加入 - 这也应该有效