How to exclude rows that don't join with another table?

前端 未结 7 820
心在旅途
心在旅途 2020-11-30 16:48

I have two tables, one has primary key other has it as a foreign key.

I want to pull data from the primary table, only if the secondary table does not

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 17:19

    Another solution is:

    SELECT * FROM TABLE1 WHERE id NOT IN (SELECT id FROM TABLE2)
    

提交回复
热议问题