Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aev-mambro2/f884de85d10cd759b8535086e3d069a3 to your computer and use it in GitHub Desktop.
Save aev-mambro2/f884de85d10cd759b8535086e3d069a3 to your computer and use it in GitHub Desktop.
Get difference between 2 lists of values in T-SQL
-- Using common table expressions
with
-- Supply list A
a (i) as (select i from (values
('6GA00215S'),
('6GU00208S'),
('6PO00396I'),
('6PO00398I')
) A(i)),
-- Supply list B
b (i) as (select i from (values
('6GA00215S'),
('6GU00208S')
) B(i))
-- Find all elements in list A that don't exist in list B
select a.i from a left join b on a.i = b.i where b.i is null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment