Select from one table where not in another

前端 未结 4 1030
情深已故
情深已故 2020-11-29 22:05

I\'m trying to find the rows that are in one table but not another, both tables are in different databases and also have different column names on the column that I\'m using

4条回答
  •  执笔经年
    2020-11-29 22:30

    To expand on Johan's answer, if the part_num column in the sub-select can contain null values then the query will break.

    To correct this, add a null check...

    SELECT pm.id FROM r2r.partmaster pm
    WHERE pm.id NOT IN 
          (SELECT pd.part_num FROM wpsapi4.product_details pd 
                      where pd.part_num is not null)
    
    • Sorry but I couldn't add a comment as I don't have the rep!

提交回复
热议问题