Often, you are only interested in some of the columns in a table. For example, to make up birthday cards for employees you might want to see the emp_lname, dept_id, and birth_date columns.
In this section, you will select each employee's birth date, last name, and department ID. Type the following:
SELECT emp_lname, dept_id, birth_date FROM employee
emp_lname |
dept_id |
birth_date |
... |
---|---|---|---|
Whitney |
100 |
1958-06-05 |
... |
Cobb |
100 |
1960-12-04 |
... |
Chin |
200 |
1966-10-30 |
... |
Jordan |
300 |
1951-12-13 |
... |
Breault |
100 |
1947-05-13 |
... |
The three columns appear in the order in which you typed them in the SELECT command. To rearrange the columns, simply change the order of the column names in the command. For example, to put the birth_date column on the left, use the following command:
SELECT birth_date, emp_lname, dept_id FROM employee
You can order rows and look at only certain columns at the same time as follows:
SELECT birth_date, emp_lname, dept_id FROM employee ORDER BY emp_lname
The asterisk in
SELECT * FROM employee
is a short form for all columns in the table.