Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Subquery

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-06-22 : 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

3271 Posts

Posted - 2006-06-22 : 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"
Go to Top of Page
   

- Advertisement -