Josh,
You're asking for something that is not possible. If there are multiple car
IDs associated with the same make and model (Ford Mustang has both 39 and 49
for IDs), there is no way to determine which ID you want. If you want the
highest ID, then you can use this query:
Select
Make,
Model,
Max(CarID)
From Cars
Group by
Make,
Model
This will return the set:
Make Model CarID
Ford Explorer 8
Ford Mustang 49
Jeep Cherokee 56
Jeep Wrangler 102
Porsche Boxster 90
--
Jeff Wilson
President
The Boolean Group, Inc.
(xxx) xxx-xxxx
Glendale, CA
"Josh Newman" <jnewman@m...> wrote in message
news:65966@s..._language...
>
> I'm trying to write an SQL query that would allow me to get the distinct
> make and model from a table called 'cars'. The problem is that I also need
> to get the CarID associated with it, so I can't use a "select distinct
> make, model, CarID from cars order by make", as each CarID is different.
>
> Here is an example of the table:
>
> Make Model CarID
> Jeep Wrangler 34
> Ford Explorer 8
> Ford Mustang 39
> Porsche Boxster 90
> Ford Mustang 49
> Jeep Wrangler 102
> Jeep Cherokee 56
>
> The results I'd like are:
>
> Ford Explorer
> Ford Mustang
> Jeep Cherokee
> Jeep Wrangler
> Porsche Boxster
>
> However, I need to be able to keep the CarID associated with each record.
>
> Thanks in advance for any help!
>
> - Josh
>
>