When I added the order by to this query it gives me this error:ORDER BY items must appear in the select list if SELECT DISTINCT is specified. What am I doing wrong?ALTER procedure [dbo].[GetT2Docs]@doc char(3),@type varchar(1)asSELECT distinct(t1.clm) as clm, n.area, n.dist, t2.doc, t1.[type], convert(char,t1.app_rcpdt, 101) as app_rcpdt, case when t1.location = 'DDS' then lorec4 when t1.location = 'FO' then t2.doc end location from T2pending t1left join T2Dibpend t2 ON t2.clm = t1.clmleft join natdocfile n on n.doc=t2.docWHERE type=@type and t2.doc=@docorder by convert(datetime,t1.app_rcpdt, 103) asc