Database Reference
In-Depth Information
By The Way SQL is very fussy about single quotes. It wants the plain, nondirectional
quotes found in basic text editors. The fancy directional quotes produced by
many word processors will produce errors. For example, the data value 'Water Sports' is
correctly stated, but 'Water Sports' is not. Do you see the difference?
Reading Specified Columns and Rows from a Single Table
So far, we have selected certain columns and all rows and we have selected all columns and
certain rows. We can combine these operations to select certain columns and certain rows by
naming the columns we want and then using the SQL WHERE clause. For example, to obtain
the SKU_Description and Department of all products in the Climbing department, we use the
SQL query:
/* *** SQL-Query-CH02-08 *** */
SELECT
SKU_Description, Department
FROM
SKU_DATA
WHERE
Department='Climbing';
The result is:
SQL does not require that the column used in the WHERE clause also appear in the
SELECT clause column list. Thus, we can specify:
/* *** SQL-Query-CH02-09 *** */
SELECT
SKU_Description, Buyer
FROM
SKU_DATA
WHERE
Department='Climbing';
where the qualifying column, Department, does not appear in the SELECT clause column list.
The result is:
By The Way Standard practice is to write SQL statements with the SELECT, FROM, and
WHERE clauses on separate lines. This practice is just a coding conven-
tion, however, and SQL parsers do not require it. You could code SQL-Query-CH02-09
all on one line as:
SELECT SKU_Description, Buyer FROM SKU_DATA WHERE Department=
'Climbing';
All DBMS products would process the statement written in this fashion. However, the
standard multiline coding convention makes SQL easier to read, and we encourage
you to write your SQL according to it.
 
Search WWH ::




Custom Search