Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT p.ProductName, c.CategoryName
- FROM Products p
- LEFT JOIN ProductCategories pc ON p.ProductID = pc.ProductID
- LEFT JOIN Categories c ON pc.CategoryID = c.CategoryID
- UNION
- SELECT p.ProductName, NULL AS CategoryName
- FROM Products p
- WHERE p.ProductID NOT IN (SELECT ProductID FROM ProductCategories);
- =================================================================
- ============================== или =============================
- =================================================================
- SELECT p.ProductName, c.CategoryName
- FROM Products p
- LEFT JOIN ProductCategories pc ON p.ProductID = pc.ProductID
- LEFT JOIN Categories c ON pc.CategoryID = c.CategoryID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement