How do I use the "DISTINCT" command

M

michaaal

I use the following SQL command in my ASP webpage...

SELECT DISTINCT CarList,CarListID FROM Model

My problem is that I would like for "CarList" to be distinct and not
"CarListID". How can I fix this problem?
 
S

Steve Kass

You must then specify what value of CarListID you wish to retrieve for a
given value of CarList. For example,

select CarList, CarListID
from Model M1
where CarListID = (
select top 1 CarListID
from Model M2
where M2.CarList = M1.CarList
order by ...
)

SK
 
M

michaaal

SELECT carlist, MIN(carlistid) AS carlistid
FROM Model
GROUP BY carlist

This is the easiest way to return the mimimum or maximum value of Carlistid
for each Carlist. If you have other columns that you want to include then
you probably need something more like the example that Steve Kass posted.

Awesome. Thanks guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top