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

AS

Aliases (AS) надає таблиці чи колонці записів даних більш зрозуміле ім'я


SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers;           // CustomerID, CustomerName  ID, Customer




SELECT CustomerName AS Customer, ContactName AS [Contact Person]    
FROM Customers;         // [] - дозволяють пробіл в назві 




SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address
FROM Customers;        // CustomerName, Address

SELECT CustomerName, CONCAT(Address,', ',PostalCode,', ',City,', ',Country) AS Address
FROM Customers;




SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName='Around the Horn' AND c.CustomerID=o.CustomerID;

SELECT Orders.OrderID, Orders.OrderDate, Customers.CustomerName
FROM Customers, Orders
WHERE Customers.CustomerName='Around the Horn' AND Customers.CustomerID=Orders.CustomerID;




Self JOIN
SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City 
ORDER BY A.City;