Datasheet

26
Chapter 1
Introducing SQL
Column Alias Names
The column alias name is dened next to the column name with a space or by using the key-
word
AS. If you want a space in the column alias name, you must enclose it in double quota-
tion marks. The case is preserved only when the alias name is enclosed in double quotation
marks; otherwise, the display will be uppercase. The following example demonstrates using
an alias name for the column heading in the previous query:
SELECT job_title AS Title, min_salary AS “Minimum Salary”
FROM jobs;
TITLE Minimum Salary
----------------------------------- --------------
President 20000
Administration Vice President 15000
Administration Assistant 3000
Finance Manager 8200
Accountant 4200
Accounting Manager 8200
… … … … …
Programmer 4000
Marketing Manager 9000
Marketing Representative 4000
Human Resources Representative 4000
Public Relations Representative 4500
19 rows selected.
In this listing, the column alias name Title appears in all capital letters because I did
not enclose it in double quotation marks.
The asterisk (*) is used to select all columns in the table. This is useful
when you do not know the column names or when you are too lazy to type
all the column names.
Ensuring Uniqueness
The DISTINCT keyword (or UNIQUE keyword) following SELECT ensures that the resulting
rows are unique. Uniqueness is veried against the complete row, not the first column. If
you need to find the unique departments in the
EMPLOYEES table, issue this query:
SELECT DISTINCT department_id
FROM employees;
95127c01.indd 26 2/18/09 6:37:09 AM