how to order rows in pl/sql?
i have a table of numbers, i want to order in ascending order if id of table is odd and descending if id is even
RainaAnja
-3
Light Poster
Recommended Answers
Jump to PostHi,
You can do that with 2 selects:
For odd ids:
SELECT * FROM table WHERE MOD(ID,2) <> 0 ORDER BY column ASC
For even ids:
SELECT * FROM table WHERE MOD(ID,2) = 0 ORDER BY column DESC
Jump to PostFollowing query will show first even ids in desc and later it will show odd ids in asc
SELECT * FROM tablename ORDER BY case when MOD(idcolumnname,2)=0 then -1 else 1 end * idcolumnname asc
All 5 Replies
Alberto Bucur
0
Junior Poster
urtrivedi
276
Nearly a Posting Virtuoso
jwenting
1,889
duckman
Team Colleague
RainaAnja
-3
Light Poster
Alberto Bucur
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.