Received: from web14707.mail.yahoo.com (web14707.mail.yahoo.com [216.136.224.124]) by postgresql.org (8.11.3/8.11.4) with SMTP id fBHGTEm73544 for ; Mon, 17 Dec 2001 11:29:15 -0500 (EST) (envelope-from chrisalbertson90278@yahoo.com) Message-ID: <20011217162919.74067.qmail@web14707.mail.yahoo.com> Received: from [130.221.203.117] by web14707.mail.yahoo.com via HTTP; Mon, 17 Dec 2001 08:29:19 PST Date: Mon, 17 Dec 2001 08:29:19 -0800 (PST) From: Chris Albertson Subject: Re: Query Help To: joe@jwebmedia.com, pgsql-general@postgresql.org In-Reply-To: <3C1E1B92.F3EC6082@jwebmedia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200112/616 X-Sequence-Number: 18713 Try this: 1) Remove DISTINCT ON(item.description) 2) Add "GROUP BY item.description" 3) Add (after SELECT) "count(pack_num)," --- Joe Koenig wrote: > I have an existing query to pull some product info from my db - there > is > a field, item.pack_num, that tells whether the item is new (1) or > used > (2). When I display the listing to the web users, I want to be able > to > tell them if a used item is available for each item in the list. > However, I want this to all be done with 1 query - so what I'm > wondering > is, is there a way to modify my exising query (below) to have it give > the the item with the pack_num of 2, if there are new and used items > in > the db. The DISTINCT ON(item.description) is there because if there > is a > new and used item, the item is listed in the db twice, once for each > pack_num (I know, bad layout - not my idea...). I don't want the > query ===== Chris Albertson Home: 310-376-1029 chrisalbertson90278@yahoo.com Cell: 310-990-7550 Office: 310-336-5189 Christopher.J.Albertson@aero.org __________________________________________________ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com