Skip to content

Instantly share code, notes, and snippets.

@realdubb
Created November 11, 2016 17:40
Show Gist options
  • Save realdubb/4d42ca2e989f0ae7b5abea7d9c134baf to your computer and use it in GitHub Desktop.
Save realdubb/4d42ca2e989f0ae7b5abea7d9c134baf to your computer and use it in GitHub Desktop.
Given a list of username as values - select the ones that don't exists in a user_table - tested in mariadb - should work in mysql
# Reference http://stackoverflow.com/a/10304316/3826642
#
# Given list of users 'bobby.flay' and 'con.artist', I want to find which of these don't exist in my Table user_table in column user_name
# 'user_namex' - can be anything you want
# a derived table name in FROM subselect is required
Select * from (
SELECT 'bobby.flay' user_namex UNION
SELECT 'con.artist'
) derived_table_name_required
where user_namex not in ( select user_name from user_table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment