需要帮助编写SQL查询

use*_*588 0 sql select

我有两个产品表Product1和Product2.在ProductId字段上有一个2 2映射.

我想要的是获取Product2.Exported字段为false的所有产品ID以及Product1中但不在Product2表中的产品ID.

现在我有两个问题,我正在尝试将其混合成一个.

SELECT ProductId FROM Product1 WHERE ProductId NOT IN(Select ProductId From Product2)
SELECT ProductId FROM Product2 WHERE Exported = 0
Run Code Online (Sandbox Code Playgroud)

Ray*_*Ray 6

使用union(或union all包含重复项):

SELECT ProductId FROM Product1 WHERE ProductId NOT IN(Select ProductId From Product2) 
union 
SELECT ProductId FROM Product2 WHERE Exported = 0 
Run Code Online (Sandbox Code Playgroud)