如何选择一个表中所有未出现在另一表中的行?
表格1:
+-----------+----------+------------+ | FirstName | LastName | BirthDate | +-----------+----------+------------+ | Tia | Carrera | 1975-09-18 | | Nikki | Taylor | 1972-03-04 | | Yamila | Diaz | 1972-03-04 | +-----------+----------+------------+
表2:
+-----------+----------+------------+ | FirstName | LastName | BirthDate | +-----------+----------+------------+ | Tia | Carrera | 1975-09-18 | | Nikki | Taylor | 1972-03-04 | +-----------+----------+------------+
表1中不在表2中的行的示例输出:
+-----------+----------+------------+ | FirstName | LastName | BirthDate | +-----------+----------+------------+ | Yamila | Diaz | 1972-03-04 | +-----------+----------+------------+
也许这样的事情应该工作:
SELECT * FROM Table1 WHERE * NOT IN (SELECT * FROM Table2)
如果您在另一条注释中提到有300列,并且想要对所有列进行比较(假设这些列的名称相同),则可以使用a NATURAL LEFT JOIN隐式联接两个表之间所有匹配的列名称,以便不必繁琐地手动输入所有加入条件:
NATURAL LEFT JOIN
SELECT a.* FROM tbl_1 a NATURAL LEFT JOIN tbl_2 b WHERE b.FirstName IS NULL