Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
willbourne
Starting Member
7 Posts |
Posted - 2005-05-25 : 04:23:31
|
I get this message [ORDER BY items must appear in the select list if SELECT DISTINCT is specified.] when I added DISTINCT to my code. My CASE WHEN includes items that appears in the select list? What do I do?SELECT DISTINCT c.customerId, c.socialSecurityNumber, c.customersName, c.phoneNumber, c.emailAddress, c.languageName, c.targetGroupName, c.customerResponsibleId, c.customerResponsibleNameFROM Customers AS c LEFT JOIN UserSettings AS u on u.AllowUserToSee = @userid WHERE (c.customerResponsibleId = @userid or c.customerResponsibleId = u.UserId)ORDER BY CASE WHEN @sortorder = 'name' then customersName WHEN @sortorder = 'latestContact' then customersName WHEN @sortorder = 'birthDate' then socialSecurityNumber WHEN @sortorder = 'totalHolding' then customersName END |
|
domus71
Starting Member
2 Posts |
Posted - 2005-05-25 : 04:41:13
|
When you use GROUP BY or DISTINCT, then ORDER BY items must appear in the select list ! |
|
|
shijobaby
Starting Member
44 Posts |
Posted - 2009-08-19 : 05:38:34
|
HiThe reasons and ways to avoid this error have discussed in this site with good examples. By making small changes in the queryhttp://sqlerror104.blogspot.com/2009/08/order-by-items-must-appear-in-select_19.html |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-08-19 : 10:47:49
|
wow! pulling up 4 year old topics! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-21 : 06:29:32
|
quote: Originally posted by russell wow! pulling up 4 year old topics!
See all his posts. He is targetting only old threadsMadhivananFailing to plan is Planning to fail |
|
|
|
|
|