SQL EXERCISE 3
PROJECTION
In relational algebra, the projection operation will retrieve a specified subset of columns from a given table. It will retrieve all of the rows but only the specified columns. The following statement illustrates the SQL format for an implementation of projection:
SQL> SELECT <column_name, …>
FROM <table_name>;
Using the table named 'EMPLOYEE' and the columns 'NAME' and 'EMPNO', retrieve all the data. The SQL SELECT command would be as follows:
SQL> SELECT NAME, EMPNO
FROM EMPLOYEE;
Note: Case is not important when entering column names, but spelling needs to match exactly the name of the column in the table.
The results table should look like this:
|
NAME |
EMPNO |
|
Wilson |
100 |
|
Smith |
101 |
|
Reed |
103 |
|
Watson |
105 |
|
Allen |
109 |
|
Turner |
110 |
|
Chen |
200 |
|
Ramirez |
210 |
|
McDonnel |
213 |
|
Simpson |
214 |
|
Di Salvo |
215 |
|
Schwartz |
220 |
Since order was not specified, the rows were returned in the order in which they reside within the table. It just so happens that they are in EMPNO order.
The SQL SELECT command is used to implement both the selection and projection operations. Most of the time your queries will combine selection and projection to retrieve data. The example below combines the selection and projection operations from the previous illustrations:
SQL> SELECT NAME, EMPNO
FROM EMPLOYEE
WHERE EMPNO = 213;
The results table is as follows:
|
NAME |
EMPNO |
|
McDonnel |
213 |
For you to try:
Go here to check your answers.
Last revised on 10/21/97 by J. Warren, Kennesaw State University
Department of Computer Science and Information Systems
![]()
Return to Oracle/SQL Tutorial Contents Page | Return to Exercise 2 | Go to SQL Exercise 4 - Using Distinct