Let us recollect how we used this command in the last section. We wanted to list the whole content of a database table, thus we used:
and got the following result:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
| Scerbakov | St.Petersburg | 443322 | 2 |
At the example of DELETE and UPDATE statements we explained how to use the WHERE clause to find a particular record within a table. The WHERE clause may be also used with the SELECT statement:
The result of this statement is:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
We actually executed a basic SQL block which consists of:
Note that the "*" symbol in the first row means that we want to see all columns in the selected record. If we want to see just specific columns from a table we have to specify our target list in the sense of the column names. For instance we may issue the following command:
This command results in:
| ccity |
| London |
The result:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
The result is:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
| Scerbakov | St.Petersburg | 443322 | 2 |
The result:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
The result:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
| Scerbakov | St.Petersburg | 443322 | 2 |
Here is the complete list of all records for these tables.
Customer table:
| cname | ccity | cphone | cid |
| Codd | London | 223344 | 1 |
| Scerbakov | St.Petersburg | 443322 | 2 |
| Harry | Vienna | 112233 | 3 |
| Manfred | Graz | 111111 | 4 |
| Jackie | Hong Kong | 666611 | 5 |
Product table:
| pname | pprice | pid |
| CPU | 23 | 1 |
| Graphic Accelerator | 12 | 2 |
| Network Interface Card | 3 | 3 |
| Hard Drive | 13 | 4 |
Transaction table:
| cid | pid | tdate | tqnt |
| 1 | 1 | 2000-11-13 | 1 |
| 1 | 2 | 2000-11-13 | 1 |
| 1 | 3 | 2000-11-13 | 2 |
| 1 | 4 | 2000-11-13 | 1 |
| 2 | 1 | 2000-11-13 | 10 |
| 2 | 2 | 2000-11-13 | 14 |
| 2 | 3 | 2000-11-13 | 35 |
| 2 | 4 | 2000-11-13 | 8 |
| 3 | 1 | 2000-11-13 | 1 |
| 4 | 2 | 2000-11-13 | 1 |
| 4 | 3 | 2000-11-13 | 1 |
| 5 | 1 | 2000-11-13 | 1 |
| 5 | 2 | 2000-11-13 | 1 |
| 5 | 3 | 2000-11-13 | 1 |
| 5 | 4 | 2000-11-13 | 1 |
Now, let us for instance get names of all customers that have bouth a CPU. We will write something like:
The result is as follows:
| cname |
| Codd |
| Scerbakov |
| Harry |
| Jackie |
Note that the predicates ( Customer.cid = Transaction.cid ) and ( Product.pid = Transaction.pid ) actually JOINS these tables over the specified attribute, i.e., over cid and pid respectively.