Re: order by question - Mailing list pgsql-admin

From Kenny W Drobnack
Subject Re: order by question
Date
Msg-id 6E25A151103CC340A1CB2CD7D44DCA4509BD84CAB4@EMASC218VS01.exchad.jpmchase.net
Whole thread Raw
In response to order by question  (Tony Liao <tonyliao@yuehetone.com>)
List pgsql-admin

I’ve never used “ORDER BY …..” in any of my queries.  If you want to get the records in order by id, you would simply do “ORDER BY id”.  If you want them by product it would be “ORDER BY product_id”.

          Your best bet (depending on what you want) is likely “ORDER BY product_id, id” which will give you the records in order by product id and then if you have multiple records with the same product_id, it will also order by id.  So your results would look like:

 

id         product_id

 

12...............3....................................

10...............4................................

25...............4.................................

33...............6...................................

40...............6..................................

43...............7...................................

17...............10................................. 

 

 

From: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org] On Behalf Of Tony Liao
Sent: Friday, June 19, 2009 5:50 AM
To: pgsql-admin@postgresql.org
Subject: [ADMIN] order by question

 

Hi,All

       for example,I have a query as this 

         select id,product_id from table_name where product_id in (6,3,4,10,7) order by .....

       the results I want to get as bellow:

id................product_id......................

33...............6...................................

40...............6..................................

12...............3....................................

25...............4.................................

10...............4................................

17...............10................................. 

43................7...................................

 

          any Idea? thanks


--
Tony Liao


This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities.

pgsql-admin by date:

Previous
From: Sergio Gabriel Rodriguez
Date:
Subject: Re: order by question
Next
From: Scott Marlowe
Date:
Subject: Re: order by question