Головна‎ > ‎SQL‎ > ‎

UNION

Коли необхідно об'єднати результати вибірки двух та більше операторів SELECT


SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;




SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;




SELECT City, Country FROM Customers
WHERE Country = 'Germany'
UNION
SELECT City, Country FROM Suppliers
WHERE Country = 'Germany'
ORDER BY City;




SELECT City, Country FROM Customers
WHERE Country = 'Germany'
UNION ALL
SELECT City, Country FROM Suppliers
WHERE Country = 'Germany'
ORDER BY City;




SELECT 'Customer' AS Type, ContactName, City, Country
FROM Customers
UNION
SELECT 'Supplier', ContactName, City, Country
FROM Suppliers