ORDER BY items must appear in the select list if SELECT DISTINCT is specified
I have sql query in which i want return rows with distinct value order by particular column. like say,i want disntict batchno from ordertable order by locationid. i have tried google also but not able to find out solution ORDER BY items must appear in the select list if SELECT DISTINCT is specified. that what i got every time i tried. when not using distinct i got output but with duplicate rows using this query Select Batchno,LocationId from Ordertbl order by case when[LocationId] =3 THEN 0 ELSE 1 END, [LocationId] if i use distinct it gives me error these are query i tried out. Select