SQL Simple -> Using Inner Join

The task is to retrive pieces of information stored in different tables using single query statement. To do this we will use INNER JOIN between Customers and Invoice tables.

-- ANSI SQL-1989 syntax
SELECT b.CustomerID, a.CustomerName, b.DocDate AS InvoiceDate
FROM Customers AS a, Invoice AS b
WHERE a.CustomerID = b.CustomerID
ORDER BY b.CustomerID;

-- ANSI SQL-1992 syntax
SELECT b.CustomerID, a.CustomerName, b.DocDate AS InvoiceDate
FROM Customers AS a INNER JOIN Invoice AS b
ON a.CustomerID = b.CustomerID
ORDER BY b.CustomerID;


The query returns results like these:
CustomerIDCustomerNameInvoiceDate
1Angelina Alba1999-01-14
1Angelina Alba2000-04-22
2Jessica Simpson1999-03-10
3Barbara Spears1999-05-17
......



sqlexamples.info