I want to get distinct Category and order there result by curdate column.
select distinct(Category)'Category' from sizes order by curdate desc
But this simple query is generating errors.
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
I’m afraid you have the same constraint for
SELECT DISTINCTas forGROUP BYclauses: namely, you cannot make use of a field that’s not declared in the fields list, because it simply doesn’t know whichcurdateto use when sorting in case there are several rows with differentcurdatevalues for the sameCategory.EDIT: try something like:
Replace MAX with MIN or whatever suits you.
EDIT2: In this case, MAX(curdate) doesn’t even have to be present in the field list since it’s used in an aggregate function.