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.
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. If you want 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
As you might have guessed, the asterisk in
SELECT * FROM employee
is a short form for all columns in the table.