By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,420 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,420 IT Pros & Developers. It's quick & easy.

ORDER by Clauses do not seem to be working correct

P: n/a
Below is the queries and the results I get when in psql monitor>

QUERY 1: SELECT id,price FROM store ORDER by price ASC;
RESULT : List from LOWEST price to HIGHEST price

QUERY 2: SELECT id,price FROM store ORDER by price DESC;
RESULT : List from HIGHEST price to LOWEST price

These work fine, but when I throw this into the mix:

QUERY 3: SELECT id,price FROM store ORDER by price,id ASC;
RESULT : List from LOWEST price to HIGHEST price (this is correct)

QUERY 4: SELECT id,price FROM store ORDER by price,id DESC;
RESULT : List from LOWEST price to HIGHEST price

As you can see on Query 4 I continue to get the same result set as
Query 3, even with the DESC order by clause. Any explanation of why? I
am using PostgreSQL 7.0.2

Thanks All!
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
In message <ad**************************@posting.google.com >, Blake
<bl***@shopwhatcom.com> writes

These work fine, but when I throw this into the mix: You are misunderstanding the semantics of this. An ASC or DESC qualifier
only applies to the immediately preceding column.
QUERY 3: SELECT id,price FROM store ORDER by price,id ASC;
RESULT : List from LOWEST price to HIGHEST price (this is correct)

This is correct because the default sort order is ascending so you have
two ascending sorts.
QUERY 4: SELECT id,price FROM store ORDER by price,id DESC;
RESULT : List from LOWEST price to HIGHEST price


This is also correct for the same reason. You have an ascending sort on
price followed by a descending sort on id.
--
Jim Smith
Because of their persistent net abuse, I ignore mail from
these domains (among others) .yahoo.com .hotmail.com .kr .cn .tw
For an explanation see <http://www.jimsmith.demon.co.uk/spam>
Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.