Home > Blockchain >  return Mysql value/s that don't find on table records
return Mysql value/s that don't find on table records

Time:09-09

i have a table

users
id collection_id
1  xwkoss
2  cw2333
3  oipopp 

And i run query:

SELECT * FROM USERS WHERE collection_id in ('xwkoss','cw2333', 'abcdeef')

that query work fine and return 2 values existing on table, but i need know, which value doesn't exist on table records example: 'abcdeef', based on search parameters

thanks

CodePudding user response:

Create a table on-the-fly and check with NOT EXISTS:

SELECT user_code
FROM
(
  SELECT 'xwkoss' AS user_code
  UNION ALL
  SELECT 'cw2333' AS user_code
  UNION ALL
  SELECT 'abcdeef' AS user_code
) codes
WHERE NOT EXISTS
(
  SELECT NULL
  FROM users
  WHERE users.user_code = codes.user_code
)
ORDER BY user_code;
  • Related