Previous Topic: Exercise 3-1Next Topic: Exercise 3-2


Retrieving Selected Columns from a Table

You just retrieved all columns and all rows from a table.

If you want to see only some of the columns, specify the names of the columns you want to see. Put a comma between column names.

How It's Done

If you want to see only the department ID and name for each department in the company, enter:

select dept_id, dept_name
       from department;

The result of this SELECT statement is a list of the values in the DEPT_ID and DEPT_NAME columns.

Where did you get the column names?

They come from the table descriptions. In this guide, the table descriptions appear in Error! Reference source not found..

The result looks like this:

DEPT_ID  DEPT_NAME -------  ---------    1120  PURCHASING - SERVICE    4200  LEASING - NEW CARS    4900  MIS    2210  SALES - NEW CARS    3520  APPRAISAL NEW CARS    5000  CORPORATE ACCOUNTING    4500  HUMAN RESOURCES    4600  MAINTENANCE    2200  SALES - USED CARS    5100  BILLING    6200  CORPORATE ADMINISTRATION    3530  APPRAISAL - SERVICE    6000  LEGAL    3510  APPRAISAL - USED CARS    1100  PURCHASING - USED CARS    5200  CORPORATE MARKETING    1110  PURCHASING - NEW CARS   17 rows processed

How does this compare with the results displayed when you specified SELECT *?

You see only the columns you selected rather than all columns.

What determines the order of the columns?

It's based on the order in which you listed the columns in your SELECT statement.