Created
July 23, 2018 11:58
-
-
Save ggodreau/07224e42ca6e2b8fdd79d36f9980c5b7 to your computer and use it in GitHub Desktop.
mySQL vs PostgreSQL exception join example
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
/* All product subcategory IDs | |
* for non bicycle frame items | |
* mySQL example using WHERE / NOT IN | |
*/ | |
SELECT p.Name, p.Color, p.ProductSubcategoryID | |
FROM Product p | |
LEFT JOIN ProductSubcategory ps on ps.ProductSubcategoryID = p.ProductSubcategoryID | |
WHERE ps.ProductSubcategoryID NOT IN | |
(SELECT ProductSubcategoryID FROM ProductSubcategory WHERE Name LIKE '%Frame%') | |
/* All product subcategory IDs | |
* for non bicycle frame items | |
* postgres example using except | |
*/ | |
SELECT p.ProductSubcategoryID | |
FROM Product p | |
LEFT JOIN ProductSubcategory ps on ps.ProductSubcategoryID = p.ProductSubcategoryID | |
EXCEPT ps.ProductSubcategoryID IN | |
(SELECT ProductSubcategoryID FROM ProductSubcategory WHERE Name LIKE '%Frame%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment