Checking whether an item does not exist in another table

前端 未结 4 1328
失恋的感觉
失恋的感觉 2020-12-15 16:07

My tables are set up something like this:

table name: process
fields: name, id_string

table name: value_seach
fields: id_string, value

I w

4条回答
  •  悲哀的现实
    2020-12-15 17:03

    In general if you want rows that don't exist in another table, then LEFT JOIN the other table and WHERE ... IS NULL to a column on the second table. Also you mentioned that you don't want rows where process.id_string is NULL.

    SELECT p.name, p.id_string
    FROM
        process p
        LEFT JOIN value_search v
            ON v.id_string = p.id_string
    WHERE
        v.id_string IS NULL
        AND p.id_string IS NOT NULL
    

    This is known as an anti-join.

提交回复
热议问题