[SQL] ORDER records based on parameters in IN clause

2005-07-13 Thread Riya Verghese
63')) GROUP BY listing_seq_id ) AS X ON X.listing_id= a.listing_id ORDER by  X.count DESC    R. Verghese       Author: Zac Date:  2005-06-29 05:122005-06-29 12:12  -700UTC To: pgsql-sql Subject: Re: [SQL] ORDER records based on parameters in IN clause > SELECT > table.* > F

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-30 Thread Daryl Richter
M.D.G. Lange wrote: Another option would be: SELECT * FROM table WHERE id=2003 OR id=1342 OR id=799 OR id=1450; This should give you the results in the right order... Per the SQL Standard, the rows of a table have no ordering. The result of a SELECT is just a derived table. Assuming a row

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-30 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > fair enough. but a simple order by id would never work. That was me, sorry, I must have been asleep when I wrote it. :) - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506300636 http://biglumber.com/x/web?pk=2529DF6AB8F79407E944

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-30 Thread Dawid Kuroczko
On 6/30/05, M.D.G. Lange <[EMAIL PROTECTED]> wrote: > Another option would be: > SELECT * FROM table WHERE id=2003 OR id=1342 OR id=799 OR id=1450; > This should give you the results in the right order... I don't think so... create temporary table seq as select * from generate_series(1,20) as g(

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-30 Thread M.D.G. Lange
Another option would be: SELECT * FROM table WHERE id=2003 OR id=1342 OR id=799 OR id=1450; This should give you the results in the right order... - Michiel Scott Marlowe wrote: On Wed, 2005-06-29 at 09:22, Russell Simpkins wrote: fair enough. but a simple order by id would never work.

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Scott Marlowe
On Wed, 2005-06-29 at 09:22, Russell Simpkins wrote: > fair enough. but a simple order by id would never work. > Try this: select *, case when id=2003 then 1 when id=1342 then 2 when id=799 then 3 when id=1450 then 4

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Michael Fuhr
On Wed, Jun 29, 2005 at 10:22:07AM -0400, Russell Simpkins wrote: > > fair enough. but a simple order by id would never work. I didn't mean to imply that it would -- I meant only that ORDER BY is necessary to guarantee a particular row order. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ ---

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Russell Simpkins
fair enough. but a simple order by id would never work. From: Michael Fuhr <[EMAIL PROTECTED]> To: Russell Simpkins <[EMAIL PROTECTED]> CC: pgsql-sql@postgresql.org Subject: Re: [SQL] ORDER records based on parameters in IN clause Date: Wed, 29 Jun 2005 05:57:23 -0600 On Wed, Jun

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Zac
SELECT table.* FROM table JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x ORDER BY x.count Bye. Sorry: I forgot join condition: SELECT table.* FROM table JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x ON (table.id = x.id) ORDER BY

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Zac
Riya Verghese wrote: select * from table where id IN (2003,1342,799, 1450) I would like the records to be ordered as 2003, 1342, 799, 1450. The outer query has no knowledge of the count(id) that the inner_query is ordering by. I think this is the real problem: outer query must know count(id)

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Michael Fuhr
On Wed, Jun 29, 2005 at 07:19:22AM -0400, Russell Simpkins wrote: > > Order by id will not do what you want, but this should. > Select * from table where id = 2003; > Union all > Select * from table where id = 1342; > Union all > Select * from table where id = 799; > Union all > Select * from tabl

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Dawid Kuroczko
On 6/27/05, Riya Verghese <[EMAIL PROTECTED]> wrote: > I have a stmt where the outer-query is limited by the results of the inner > query. I would like the outer query to return records in the same order as > the values provided in the IN clause (returned form the inner query). > > The inner_quer

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Russell Simpkins
>> when I say >> select * from table where id IN (2003,1342,799, 1450) >> I would like the records to be ordered as 2003, 1342, 799, 1450. >Just say: >select * from table where id IN (2003,1342,799, 1450) ORDER BY id; >If that doesn't work, you will have to be more specific and send us the exact qu

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-28 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > when I say > select * from table where id IN (2003,1342,799, 1450) > I would like the records to be ordered as 2003, 1342, 799, 1450. Just say: select * from table where id IN (2003,1342,799, 1450) ORDER BY id; If that doesn't work, you will hav

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-28 Thread Michael Fuhr
On Mon, Jun 27, 2005 at 09:15:15AM -0700, Riya Verghese wrote: > > I have a stmt where the outer-query is limited by the results of the > inner query. I would like the outer query to return records in the same > order as the values provided in the IN clause (returned form the inner > query). If y

[SQL] ORDER records based on parameters in IN clause

2005-06-27 Thread Riya Verghese
I have a stmt where the outer-query is limited by the results of the inner query. I would like the outer query to return records in the same order as the values provided in the IN clause (returned form the inner query). The inner_query is returning id’s ordered by count(id) , i.e by most