Re: [SQL] Join issue on a maximum value

2004-04-26 Thread Jeremy Semeiks
On Wed, Apr 21, 2004 at 02:29:34PM -0400, Heflin wrote: > OK, it's been a while since I've had to do anything remotely complex in > SQL, so this may just be a pure brain block on my part. > ... > > So a basic JOIN gets this: > > SELECT auction.auction_id, image.image_id, image.image_descr > FROM

Re: [SQL] Join issue on a maximum value

2004-04-26 Thread Atesz
On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin wrote: > > SELECT auction.auction_id, image.image_id, image.image_descr FROM > auction JOIN image ON auction.auction_id = image.auction_id WHERE > auction.auction_owner = 'Mabel'; > In my opinion there are 2 problem: how can you make the query

Re: [SQL] Join issue on a maximum value

2004-04-22 Thread Tom Lane
Heflin <[EMAIL PROTECTED]> writes: > Bruno Wolff III wrote: >> The postgres specific way of doing this is: >> SELECT DISTINCT ON (auction.auction_id) >> auction.auction_id, image.image_id, image.image_descr >> FROM auction JOIN image ON auction.auction_id = image.auction_id >> WHERE auction.auction

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Bruno Wolff III
On Wed, Apr 21, 2004 at 16:28:10 -0400, Heflin <[EMAIL PROTECTED]> wrote: > > > >The postgres specific way of doing this is: > >SELECT DISTINCT ON (auction.auction_id) > > auction.auction_id, image.image_id, image.image_descr > > FROM auction JOIN image ON auction.auction_id = image.auction_id

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Edmund Bacon
Two choices that work: Either add another JOIN in which retrieves the MAX(image_id) for each auction: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image USING(auction_id) JOIN ( SELECT auction_id, MAX(image_id) AS image_id FROM image

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Bruno Wolff III
On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin <[EMAIL PROTECTED]> wrote: > > So a basic JOIN gets this: > > SELECT auction.auction_id, image.image_id, image.image_descr > FROM auction JOIN image ON auction.auction_id = image.auction_id > WHERE auction.auction_owner = 'Mabel'; > > Now the prob

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
Bruno Wolff III wrote: On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin <[EMAIL PROTECTED]> wrote: So a basic JOIN gets this: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image ON auction.auction_id = image.auction_id WHERE auction.auction_owner = 'Mabel'; Now

[SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
OK, it's been a while since I've had to do anything remotely complex in SQL, so this may just be a pure brain block on my part. I have 2 tables, auction and image, defined like this: Table "public.auction" Column | Type |