Checking whether an item does not exist in another table

前端 未结 4 1329
失恋的感觉
失恋的感觉 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:00

    The query you want should look something like this. Note that a JOIN will be significantly faster than a subquery in the WHERE clause.

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

    An equally valid variant of the query above would be:

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

提交回复
热议问题