ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

23 Feb 2010 01:02:51
how to use the ORDER BY with DISTINCT in Sql Query. Just look at the following query. select distinct AcademicYear from IVLESToolUsage order by cast(SUBSTRING(LTRIM(RTRIM(AcademicYear)),9,4) as int) DESC AcademicYear-char(15) When you are execute you will get following error message. Error:[color=#FF0000]ORDER BY items must appear in the select list if SELECT DISTINCT is specified.[/color] Solution: [color=#0000FF] select AliasTable.AcadmicYearAL from ( select DISTINCT LTRIM(RTRIM(AcademicYear)) as AcadmicYearAL from IVLESToolUsage) as AliasTable ORDER BY cast(SUBSTRING(LTRIM(RTRIM(AliasTable.AcadmicYearAL)),9,4) as int) DESC [/color] Thank you
Gold   Boarder
Posts: 156
From 03-Jun-2009
You're Points: 1106
Bookmark
^ Scroll to Top