Advertisement
Infiniti_Inter

Запрос SQLный

Aug 5th, 2024 (edited)
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.67 KB | None | 0 0
  1. SELECT p.ProductName, c.CategoryName
  2. FROM Products p
  3. LEFT JOIN ProductCategories pc ON p.ProductID = pc.ProductID
  4. LEFT JOIN Categories c ON pc.CategoryID = c.CategoryID
  5. UNION
  6. SELECT p.ProductName, NULL AS CategoryName
  7. FROM Products p
  8. WHERE p.ProductID NOT IN (SELECT ProductID FROM ProductCategories);
  9.  
  10. =================================================================
  11. ==============================  или =============================
  12. =================================================================
  13.  
  14. SELECT p.ProductName, c.CategoryName
  15. FROM Products p
  16. LEFT JOIN ProductCategories pc ON p.ProductID = pc.ProductID
  17. LEFT JOIN Categories c ON pc.CategoryID = c.CategoryID
Tags: sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement