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

前端 未结 7 803
心在旅途
心在旅途 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:05

    SELECT P.*
    FROM primary_table P
    LEFT JOIN secondary_table S on P.id = S.p_id
    WHERE S.p_id IS NULL
    

提交回复
热议问题