SQL: check which identifier already exists

Let's say I have a list of identifiers, and I want to see if rows with these identifiers exist in my SQL database. Is there one SQL command that I can execute to return a subset of the list of identifiers that have not yet been presented in the database? I could iterate over each identifier in my code and produce a separate SQL check for each identifier, but that sounds inefficient.

I am trying to do this against sqlite database. thank you

+3
source share
2 answers

Drop the identifiers into the table, and then try:

SELECT C.id
FROM checkids C
LEFT JOIN mytable M
ON M.id = C.id
WHERE M.id IS NULL
+3
source

IN; , 1, 2, 8 42:

SELECT id
FROM tbl
WHERE id IN (1, 2, 8, 42);
0

Source: https://habr.com/ru/post/1757507/


All Articles