| Author |
Topic  |
|
|
AskSQLTeam
Ask SQLTeam Question
USA
0 Posts |
Posted - 06/22/2006 : 09:53:56
|
Bryan writes "Hello, and thank you in advance for any help you can give.
I'm trying to design a query to pull multiple rows from one table, and a single row from another table where an auction Id would be equal in both tables. Here's the setup
Table 1 AuctionID - PK AuctionName AuctionDate AuctionOptions ...
Table 2 AuctionID - FK BidID BidAmount Bidder ...
Every record existing in table 1 should be returned, and only the TOP record from table two as an expression, giving me the high bid amount for each auction, since each auction will have multiple bids, I need only the top record.
Thanks for all your help" |
|
|
Lumbago
Norsk Yak Master
Norway
3241 Posts |
Posted - 06/22/2006 : 09:58:09
|
SELECT a.AuctionID, a.ActionName, ISNULL(MAX(b.BidAmount), 0) AS HighestBid FROM table1 a LEFT OUTER JOIN table2 b ON a.AuctionID = b.a.AuctionID GROUP BY a.AuctionID, a.ActionName
-- Lumbago "Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
| |
Topic  |
|
|
|