Queries from more than one table can be performed. Usually these tables share a common field.
Such queries are also carried out by SELECT statements, and the syntax is the same as that for single-table queries. However, field names appear in the expressions in such queries should contain the table name (as <table_name>.<field_name>) to avoid confusion.
The following examples show how a multiple-table query can be performed (click here to see the contents of the tables s6a and books).
Retrieve the students' names, books' Call IDs and due dates from the tables s6a and books where the Student ID in s6a is the same as that in books and the due date is before November 15, 1999. List these items in ascending order of the due dates. | |||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT s6a.name,
books.call_id, books.due_date FROM s6a, books WHERE s6a.stud_id = books.stud_id AND books.due_date < {11/15/99} ORDER BY books.due_date ASC |
|||||||||||||||||||||||||||||||||||||||||||||||||||
Output:
|
Retrieve the students' names, books' Call IDs, email addresses and due dates from the tables s6a and books where the Student ID in s6a is the same as that in books and the due date is before November 1, 1999. List these items in desscending order of the due dates. | ||||||||||||||||||||||||
SELECT s6a.name,
s6a.email, books.call_id, books.due_date FROM s6a, books WHERE s6a.stud_id = books.stud_id AND books.due_date < {11/01/99} ORDER BY books.due_date DESC |
||||||||||||||||||||||||
Output:
|