| Author |
Topic |
|
eevans
Starting Member
48 Posts |
Posted - 2009-02-13 : 10:36:45
|
| Here is my ORDER BY statement...ORDER BY (CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END)I am using it in conjunction with a SELECT DISTINCT statement.When I execute the query, I receive the following error message..."ORDER BY items must appear in the select list if SELECT DISTINCT is specified."The class_code column is contained in the SELECT DISTINCT statement.Any suggestions? Thanks. |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-02-13 : 10:39:49
|
| Maybe this is the reasonclas_code <> class_cdeCan you please post the whole Select? |
 |
|
|
eevans
Starting Member
48 Posts |
Posted - 2009-02-13 : 10:59:36
|
| "clas_code <> class_cde"Not sure what you mean.Also, I might mention that the when I change the SELECT DISTINCT statement to a plain SELECT statement, the ORDER BY statement works fine.Thanks. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-13 : 11:01:16
|
| Post your whole select statement. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-13 : 11:05:19
|
quote: Originally posted by eevans Here is my ORDER BY statement...ORDER BY (CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END)I am using it in conjunction with a SELECT DISTINCT statement.When I execute the query, I receive the following error message..."ORDER BY items must appear in the select list if SELECT DISTINCT is specified."The class_code column is contained in the SELECT DISTINCT statement.Any suggestions? Thanks.
you need to include the case..when...construct in select as wellie. likeSELECT DISTINCT CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END,....ORDER BY (CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END)or you can use like this alsoSELECT DISTINCT OrdField,..FROM(SELECT CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END AS OrdField,.....)tORDER BY OrdField |
 |
|
|
eevans
Starting Member
48 Posts |
Posted - 2009-02-13 : 11:17:50
|
| visakh16,Your solution works. However, I end up with an unnecessary column containing the ordering values (1,2,3,4) in place of the actual values (SR,JR,SO,FR). Is there any way to eliminate this extra column? Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-13 : 11:22:12
|
quote: Originally posted by eevans visakh16,Your solution works. However, I end up with an unnecessary column containing the ordering values (1,2,3,4) in place of the actual values (SR,JR,SO,FR). Is there any way to eliminate this extra column? Thanks.
nope. you cant eliminate it in query if you need to use DISTINCT. b/w why are you using distinct here? |
 |
|
|
eevans
Starting Member
48 Posts |
Posted - 2009-02-13 : 11:26:35
|
| Thanks. I appreciate you help. The query I'm writing has a lot more variables that requires me to use SELECT DISTINCT |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2009-02-13 : 12:21:24
|
Couldn't you just put the DISTINCT part into a subquery?SELECT A.*FROM ( SELECT DISTINCT class_cde, ... FROM ... ) AS AORDER BY(CASE WHEN class_cde='sr' THEN 1WHEN class_cde='jr' THEN 2WHEN class_cde='so' THEN 3WHEN class_cde='fr' THEN 4END) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-13 : 12:36:46
|
quote: Originally posted by eevans Thanks. I appreciate you help. The query I'm writing has a lot more variables that requires me to use SELECT DISTINCT
lot more variables or values? |
 |
|
|
|