Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select distinct returns duplicates 1

Status
Not open for further replies.

brownfox

Programmer
Jan 5, 2003
173
GB
I only want to return one row for driver_guide 46 but "select distinct driver_guide,driver_make..." returns both records:
Code:
[u]driver_guide| driver_make[/u] 
46          |Jaguar 
46          |Ford
Any help much appreciated.
 
of course :)

the function of DISTINCT is to ensure that all result rows are unique

you have two columns in the SELECT

therefore you get only distinct combinations of those two values

in the example you show, those rows are unique

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
OK I get that but how do I just get just one row? Do I have to join the table on itself using an alias or something?
 
... get just one row?
but which one? [smile]

You could use group by and aggregate functions,
something like this:
Code:
select driver_guide, min(driver_make)
from your_table
group by driver_guide;
hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top