SELECT that returns list of values not occurring in any row

后端 未结 6 1573
星月不相逢
星月不相逢 2020-12-14 06:02

Query:

select id from users where id in (1,2,3,4,5)

If the users table contains ids 1, 2, 3, this would return 1, 2, and 3. I want a query

6条回答
  •  天命终不由人
    2020-12-14 06:46

    Sorry, I cannot add comments, @Austin,

    You have my +1.

    Anyway, not sure if this works on mysql, but change all that atomic selects concatenated unions for a value set, so you have something like that:

    SELECT id FROM (
        VALUES (1), (2), (3), (4), (5)
    ) AS list(id)
    LEFT JOIN users USING (id)
    WHERE users.id IS NULL
    

提交回复
热议问题