Tuesday, July 03, 2007

Using DISTINCT in Select Statement

When you use DISTINCT in a Select statement, you are saying that you only want one row in the result set for each distinct set of values. The result set will not have any two rows that have the same values in every column.

Let's say in table SOP30300, you have the following data:
INV001 Items: ABC, DEF, GHI
INV002 Items: DEF, JKL, MNO
INV003 Items: MNO

Then you run this statement:
SELECT DISTINCT itemnmbr
FROM dbo.SOP30300

The result set should be:
ABC,DEF,GHI,JKL,MNO

4 comments:

Anonymous said...

using GROUP BY will produce the same result.

ex: SELECT itemnmbr
FROM dbo.SOP30300
group by itemnmbr

Mills
http://gp-dynamics.com

adam said...

Hello I just entered before I have to leave to the airport, it's been very nice to meet you, if you want here is the site I told you about where I type some stuff and make good money (I work from home): here it is

Anonymous said...

Nice dispatch and this enter helped me alot in my college assignement. Gratefulness you on your information.

Anonymous said...

Nice brief and this enter helped me alot in my college assignement. Gratefulness you as your information.