0

Sample mysql table:

carnum,cartype,carname
1,sportscar,mustang
2,sportscar,mustang GT
3,sportscar,mustang GT

When I run this query:

SELECT carname, cartype
FROM cars
GROUP BY cartype

I get:

mustang,sportscar

What I want is:

mustang GT,sportscar

Is there a way to make the group use the most recent carname (mustang GT) rather than the first one (mustang)? I tried sorting in various ways but had no luck.

Thanks very much.

2 Answers2

0

try with this one

select carname, cartype from cars 
where carnum in(
select max(carnum) from cars group by cartype
); 
neiha
  • 171
  • 5
-1

You may want to try:

Select Distinct carname, cartype FROM cars

or

Select top 1 carname, cartype FROM cars Order by carname

This will give you what you want in this case, but depending on your final goal, may not be ideal. If you provide more details, we may be able to help more.

David Manheim
  • 2,553
  • 2
  • 27
  • 42