ORDER records based on parameters in IN clause - Mailing list pgsql-sql

From Riya Verghese
Subject ORDER records based on parameters in IN clause
Date
Msg-id BBA4F47BB0CEDD4D8ADD2FE21E2823673116C5@dhost002-37.dex002.intermedia.net
Whole thread Raw
List pgsql-sql

Thanks!

This worked beautifully.

 

Here’s what I have:

SELECT a.listing_ id FROM cls.listings  a

JOIN (SELECT listing_id,count(listing_id) AS count FROM cls.tagslistings 

WHERE    cust_id =27

AND tag_id IN (SELECT tag_id FROM cls.tags WHERE tag_name IN ('toys','263'))

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:12  -700To: 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... 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

     x.count

 

pgsql-sql by date:

Previous
From: "Ramakrishnan Muralidharan"
Date:
Subject: Re: two sums in one query
Next
From: Frank Hagstrom
Date:
Subject: Possible to use a table to tell what table to select from?