MYSQL choosing value used of column with different values when Grouping -
sample mysql table:
carnum,cartype,carname 1,sportscar,mustang 2,sportscar,mustang gt 3,sportscar,mustang gt
when run query:
select carname, cartype cars group cartype
i get:
mustang,sportscar
what want is:
mustang gt,sportscar
is there way make group use recent carname (mustang gt) rather first 1 (mustang)? tried sorting in various ways had no luck.
thanks much.
try 1
select carname, cartype cars carnum in( select max(carnum) cars group cartype );
Comments
Post a Comment