Friday, January 8, 2010

Select 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 redundancies. 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"

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

1 comment:

  1. This is a great reading. Thanks for sharing this information.We have few readers who would like to read this stuff. We will pass it on to our readers for more feedback. We are dealing with seo agency and would like to get feedback from you too.This is a nice postings indeed. Thanking You. search engine optimization los angeles

    ReplyDelete