Skip to content
Advertisement

Select id from input list NOT present in database

With MySql vers 8.0:

Then,

The first two statements execute successfully. The next statement does not, however. My goal is to return a list of unused cid’s from the input table [1, 2]:

In theory, I’d like the output to be ‘2’, since it has not yet been added. The aforementioned query was inspired by Remus’s answer on https://dba.stackexchange.com/questions/37627/identifying-which-values-do-not-match-a-table-row

Advertisement

Answer

This is at least the correct syntax for what you are trying to do.

If this query is anything more than a learning exercise though I’d rethink the approach, storing these ‘1’ and ‘2’ values (or however many there ends up being) in their own table

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement