sql queries the id that does not exist in the database and returns

There is such a requirement in the project: when importing (student registration development language) excel form, if the id exists in the database, the import can be executed, if the language id does not exist, the front end will be prompted, and the language id does not exist!

A brief description is: Give you a few IDs and return IDs that do not exist in the language table?

The language table data is as follows: The
Insert picture description here
sql statement is as follows:

select B.id
  from (select 1 as id from language
        union
        select 2 as id from language
        union
        select 26 as id from language
        union
        select 27 as id from language
        ) B
  left join language as A
    on A.id = B.id
 where A.id is null;

The query results are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44146379/article/details/108501932