Database Reference
In-Depth Information
Notice that some rows are duplicated in these results. The data in the first and second
row, for example, are identical. We can eliminate duplicates by using the SQL DISTINCT
keyword , as follows:
/* *** SQL-Query-CH02-03 *** */
SELECT
DISTINCT Buyer, Department
FROM
SKU_DATA;
The result of this statement, where all of the duplicate rows have been removed, is:
By The Way The reason that SQL does not automatically eliminate duplicate rows is
that it can be very time consuming to do so. To determine if any rows are
duplicates, every row must be compared with every other row. If there are 100,000
rows in a table, that checking will take a long time. Hence, by default duplicates are
not removed. However, it is always possible to force their removal using the DISTINCT
keyword.
Suppose that we want to view all of the columns of the SKU_DATA table. To do so, we can
name each column in the SELECT statement as follows:
/* *** SQL-Query-CH02-04 *** */
SELECT
SKU, SKU_Description, Department, Buyer
FROM
SKU_DATA;
The result will be a table with all of the rows and all four of the columns in SKU_DATA:
However, SQL provides a shorthand notation for querying all of the columns of a table.
The shorthand is to the SQL asterisk (*) wildcard character to indicate that we want all
the columns to be displayed:
/* *** SQL-Query-CH02-05 *** */
SELECT *
FROM
SKU_DATA;
 
Search WWH ::




Custom Search