|
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:
| CustomerID | CustomerName | InvoiceDate |
| 1 | Angelina Alba | 1999-01-14 |
| 1 | Angelina Alba | 2000-04-22 |
| 2 | Jessica Simpson | 1999-03-10 |
| 3 | Barbara Spears | 1999-05-17 |
| .. | .. | .. |
|