Table1 (id, name) Table2 (id, name)
查询:
SELECT name
FROM table2
-- that are not in table1 already
Table1 (id, name) Table2 (id, name)
查询:
SELECT name
FROM table2
-- that are not in table1 already
当前回答
那对我来说很有用
SELECT *
FROM [dbo].[table1] t1
LEFT JOIN [dbo].[table2] t2 ON t1.[t1_ID] = t2.[t2_ID]
WHERE t2.[t2_ID] IS NULL
其他回答
这是纯集合论你可以用减号运算来实现。
select id, name from table1
minus
select id, name from table2
SELECT <column_list>
FROM TABLEA a
LEFTJOIN TABLEB b
ON a.Key = b.Key
WHERE b.Key IS NULL;
https://www.cloudways.com/blog/how-to-join-two-tables-mysql/
你可以使用以下查询结构:
SELECT t1.name FROM table1 t1 JOIN table2 t2 ON t2。Fk_id != t1.id;
表1:
id | name |
---|---|
1 | Amit |
2 | Sagar |
表二:
id | fk_id | |
---|---|---|
1 | 1 | amit@ma.com |
输出:
name |
---|
Sagar |
看到查询:
SELECT * FROM Table1 WHERE
id NOT IN (SELECT
e.id
FROM
Table1 e
INNER JOIN
Table2 s ON e.id = s.id);
从概念上讲是:在子查询中获取匹配的记录,然后在主查询中获取不在子查询中的记录。
我尝试了以上所有的解决方案,但它们都不适合我。下面的查询对我有用。
SELECT NAME
FROM table_1
WHERE NAME NOT IN
(SELECT a.NAME
FROM table_1 AS a
LEFT JOIN table_2 AS b
ON a.NAME = b.NAME
WHERE any further condition);