[SQL] ORDER records based on parameters in IN clause

2005-07-13 Thread Riya Verghese
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-2905:122005-06-2912:12 -700UTC To:pgsql-sql Subject:Re: [SQL] ORDER records based on parameters in IN clause SELECT table.* FROM table JOIN (SELECT id, count(id) AS count FROM

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(id);

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

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_query is

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 table where

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 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 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 29, 2005 at 07:19

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-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 you

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 have

[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 ids ordered by count(id) , i.e by most