X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7357B52A38 for ; Thu, 7 Jul 2005 18:01:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49855-08 for ; Thu, 7 Jul 2005 21:01:51 +0000 (GMT) Received: from dhost002-37.dex002.intermedia.net (dhost002-37.dex002.intermedia.net [64.78.21.122]) by svr1.postgresql.org (Postfix) with ESMTP id F0C8D52A2B for ; Thu, 7 Jul 2005 18:01:47 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C58337.1247A04A" Subject: ORDER records based on parameters in IN clause Date: Thu, 7 Jul 2005 14:01:39 -0700 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] ORDER records based on parameters in IN clause Thread-Index: AcWDNxHSScvE5SvySMaUPwkyhqvfyA== From: "Riya Verghese" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.104 tagged_above=0 required=5 tests=AWL, HTML_MESSAGE, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200507/118 X-Sequence-Number: 22096 This is a multi-part message in MIME format. ------_=_NextPart_001_01C58337.1247A04A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks! This worked beautifully. =20 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 =3D27=20 AND tag_id IN (SELECT tag_id FROM cls.tags WHERE tag_name IN ('toys','263')) GROUP BY listing_seq_id=20 ) AS X ON X.listing_id=3D a.listing_id=20 ORDER by X.count DESC =20 =20 R. Verghese =20 =20 =20 Author: Zac Date: 2005-06-29 05:12 2005-06-29 12:12 -700 UTC 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... your subquery) AS x > ORDER BY > x.count >=20 > Bye. Sorry: I forgot join condition: SELECT table.* FROM table JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x ON=20 (table.id =3D x.id) ORDER BY x.count =20 ------_=_NextPart_001_01C58337.1247A04A Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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 = =3D27

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=3D = a.listing_id

ORDER by  X.count DESC  =

 

R. = Verghese

 

 

 

Author: Zac
Date:  2005-06-29 05:12&= nbsp; -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 =3D x.id)
ORDER BY

     =
x.count

 

------_=_NextPart_001_01C58337.1247A04A--