SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Subquery
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 06/22/2006 :  09:53:56  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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
3271 Posts

Posted - 06/22/2006 :  09:58:09  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000