MySQL - How to get results that were not found

0

I need to check which IDs were not found in the table.

SELECT * FROM example_table WHERE id IN (123, 124, 125, 126, 127)

Since of (123, 124, 125, 126, 127) , in the table I only have (123, 124) .

The result I'm expecting is (125, 126, 127) .

I've explored the Sub-Querys option but I can not figure out how I'll finish.

    
asked by anonymous 24.05.2018 / 15:45

1 answer

0

Remembering that the following solution fits when the need to use is something that compares to what is used in NOT IN, IN . Something with little values. See if this helps you with something:

SELECT ids.id FROM (SELECT '123' AS id
                    UNION SELECT '124'
                    UNION SELECT '125' 
                    UNION SELECT '126'
                    UNION SELECT '127') ids
LEFT JOIN example_table ex
  ON ex.id = ids.id
WHERE ex.id IS NULL

Output:

id
125
126
127

I have tested here. Source: link

    
24.05.2018 / 16:08