Often, you are interested in only columns in a table. For example, to make up birthday cards for employees you might want to see the Surname, DepartmentID and BirthDate columns.
This example selects each employee's birth date, last name, and department ID. Type the following:
SELECT Surname, DepartmentID, BirthDate FROM Employees
Surname |
DepartmentID |
BirthDate |
---|---|---|
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 BirthDate column on the left, use the following command:
SELECT BirthDate, Surname, DepartmentID FROM Employees
You can order rows and look at only certain columns at the same time as follows:
SELECT BirthDate, Surname, DepartmentID FROM Employees ORDER BY Surname
The asterisk in
SELECT * FROM Employees
is a short form for all columns in the table.