Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeveltstra/c496d6debb20785f56a16a6059d13ffc to your computer and use it in GitHub Desktop.
Save aeveltstra/c496d6debb20785f56a16a6059d13ffc to your computer and use it in GitHub Desktop.
TSQL select values from list which do not exist in table
/**
* Introducing the EXCEPT operator.
* To select values from a list, use the VALUES operator, and assign that to a table keyword, like so:
*/
SELECT dagnaam FROM (VALUES
('maandag'),
('dinsdag'),
('woensdag')
) E(dagnaam);
/**
* To select all those in that list, except for those that exist in a table, use the EXCEPT operator:
*/
SELECT dagnaam FROM (VALUES
('maandag'),
('dinsdag'),
('woensdag')
) E(dagnaam)
EXCEPT
SELECT name from days where language = 'nl';
/**
* The result is the list of missing values.
*
* Happy coding!
*/
@aeveltstra
Copy link
Author

TSQL or T-SQL stands for Transact SQL. It is an SQL dialect used by Microsoft in their DBMS, SQL Server Management Studio (SSMS for short).

@aeveltstra
Copy link
Author

[https://learn.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-except-and-intersect-transact-sql?view=sql-server-ver16](Microsoft Learn: Except and Intersect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment