SQL Tutorial


SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL ORDER BY
SQL Functions
SQL COUNT
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL JOIN
SQL OUTER JOIN
SQL Subquery
SQL UNION
SQL UNION ALL
SQL INTERSECT
SQL MINUS














Data Warehousing & Business Intelligence
Area Codes Info
State Info
HTML Tutorial


















Home
SQL Commands
Table Manipulation
SQL Syntax

SQL DISTINCT

The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily mean that there will be redundencies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is to add DISTINCT after SELECT. The syntax is as follows:

SELECT DISTINCT "column_name"
FROM "table_name"

For example, to select all distinct stores in Table Store_Information,

Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999

we key in,

SELECT DISTINCT store_name FROM Store_Information

Result:

store_name
Los Angeles
San Diego
Boston


Next Section

Site Map   |   Resources

1