|
I am getting unwanted duplicate rows in my result set, so I added the
DISTINCT keyword to my outermost SELECT. My working query then returned
the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2
Message: An expression in the ORDER BY clause in the following
position, or starting with "CASE..." in the "ORDER BY" clause is not
valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098,
SQLERRMC: 2;-214;42822;CASE...|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE
WHEN t01.lot_numb IS NULL AND
t01.lot_suffix IS NOT NULL
THEN 0
ELSE t01.lot_numb
END,
COALESCE(t01.lot_suffix, ''),
animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The
clause works when there is no DISTINCT. | |
Share:
|
Bob Stearns wrote: I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-214;42822;CASE...|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE WHEN t01.lot_numb IS NULL AND t01.lot_suffix IS NOT NULL THEN 0 ELSE t01.lot_numb END, COALESCE(t01.lot_suffix, ''), animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The clause works when there is no DISTINCT.
I take a guess and assume that perhaps some of the columns/expressions
in the order by are not in the select list. That's why Db2 is cranky on
the DISTINCT. The hidden columns get in the way.
Push the DISTINCT into a subquery an then ORDER the result:
SELECT ... FROM (SELECT DISTINCT....) AS X
ORDER BY ...
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab | | |
Serge Rielau wrote: Bob Stearns wrote:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-214;42822;CASE...|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE WHEN t01.lot_numb IS NULL AND t01.lot_suffix IS NOT NULL THEN 0 ELSE t01.lot_numb END, COALESCE(t01.lot_suffix, ''), animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The clause works when there is no DISTINCT.
I take a guess and assume that perhaps some of the columns/expressions in the order by are not in the select list. That's why Db2 is cranky on the DISTINCT. The hidden columns get in the way. Push the DISTINCT into a subquery an then ORDER the result: SELECT ... FROM (SELECT DISTINCT....) AS X ORDER BY ...
You got it in one. I'm selecting functions of t01.lot_numb and
t01.lot_suffix, but not those columns by themselves.
I had the sql reference manual open to page 555 ff. (for v8) and saw no
mention of having order by columns in the select list when distinct is
used. While the message correct in this case, it could be more informative. | | |
Bob Stearns wrote: Serge Rielau wrote: Bob Stearns wrote:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-214;42822;CASE...|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE WHEN t01.lot_numb IS NULL AND t01.lot_suffix IS NOT NULL THEN 0 ELSE t01.lot_numb END, COALESCE(t01.lot_suffix, ''), animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The clause works when there is no DISTINCT.
I take a guess and assume that perhaps some of the columns/expressions in the order by are not in the select list. That's why Db2 is cranky on the DISTINCT. The hidden columns get in the way. Push the DISTINCT into a subquery an then ORDER the result: SELECT ... FROM (SELECT DISTINCT....) AS X ORDER BY ... You got it in one. I'm selecting functions of t01.lot_numb and t01.lot_suffix, but not those columns by themselves.
I had the sql reference manual open to page 555 ff. (for v8) and saw no mention of having order by columns in the select list when distinct is used. While the message correct in this case, it could be more informative.
Punch the feedback button on the topic of the DB2 zOS information center :-)
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab | | |
Serge Rielau wrote: Bob Stearns wrote:
Serge Rielau wrote:
Bob Stearns wrote:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2 Message: An expression in the ORDER BY clause in the following position, or starting with "CASE..." in the "ORDER BY" clause is not valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-214;42822;CASE...|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE WHEN t01.lot_numb IS NULL AND t01.lot_suffix IS NOT NULL THEN 0 ELSE t01.lot_numb END, COALESCE(t01.lot_suffix, ''), animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The clause works when there is no DISTINCT.
I take a guess and assume that perhaps some of the columns/expressions in the order by are not in the select list. That's why Db2 is cranky on the DISTINCT. The hidden columns get in the way. Push the DISTINCT into a subquery an then ORDER the result: SELECT ... FROM (SELECT DISTINCT....) AS X ORDER BY ... You got it in one. I'm selecting functions of t01.lot_numb and t01.lot_suffix, but not those columns by themselves.
I had the sql reference manual open to page 555 ff. (for v8) and saw no mention of having order by columns in the select list when distinct is used. While the message correct in this case, it could be more informative.
Punch the feedback button on the topic of the DB2 zOS information center :-)
Cheers Serge
I must have the wrong URL. I see no feedback button (but it's late). The
URL I'm using is: http://publib.boulder.ibm.com/infoce.../v8//index.jsp | | |
Gert van der Kooij wrote: In article <rN************@fe05.lga>, rs**********@charter.net says...
I must have the wrong URL. I see no feedback button (but it's late). The URL I'm using is:
http://publib.boulder.ibm.com/infoce.../v8//index.jsp
At the bottom of that page are a couple of links, one of them is the feedback link.
FYI, in DB2 Viper there actually is a button at the topic level I believe.
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by bhieb |
last post: by
|
1 post
views
Thread by Bryan Zash |
last post: by
|
3 posts
views
Thread by JSubadhra |
last post: by
|
2 posts
views
Thread by YFS DBA |
last post: by
|
6 posts
views
Thread by Bob Stearns |
last post: by
|
reply
views
Thread by EJO |
last post: by
|
8 posts
views
Thread by sehiser |
last post: by
|
5 posts
views
Thread by Justin Fancy |
last post: by
| | | | | | | | | | | |