Created
October 4, 2023 16:35
-
-
Save aeveltstra/c496d6debb20785f56a16a6059d13ffc to your computer and use it in GitHub Desktop.
TSQL select values from list which do not exist in table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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! | |
*/ |
[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
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).