| | |
SQL Help!!!
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
I am having trouble with one thing on my project. I have already created the following table and inserted all of the information into it.
Items
ItemID Description BidFloor
100 1943 Monopoly game 80
101 1972 Ford Pinto Station Wagon 80
102 1.5 L 1921 Chateau Neuf du Pape 1,000
103 Ruby Slipper from Wizard of Oz 50,000
Bidders
BidderID LastName FirstName CreditLimit SSNO
1 Jones Rick 1,000 111-22-1111
2 Morris Gary 2,000,000 222-11-1111
3 Sussman David 25,000 333-33-8777
Bids
BidNumber ItemID BidderID Amount BidChannel
1 102 2 1,000 Phone
2 100 1 81 In Person
3 102 3 1,100 In Person
4 102 2 1,500 Phone
5 100 3 100 In Person
6 101 1 81 In Person
Now the problem that I am having is this. Here is the next set of instructions:
Write an SQL script which produces a query showing every single itemID, Description, Bidfloor, winning bid amount, winningBidNumber, winning bidder last name, and winning bidder first name. Your list should include items that were not bid on and should be in order from the lowest winning bid price to the highest winning bid price. Name your script winningbids.sql
I have it working except I don't know how to get the items that no one bids on. Heres my code for this part:
Any advice is greatly appreciated.
Items
ItemID Description BidFloor
100 1943 Monopoly game 80
101 1972 Ford Pinto Station Wagon 80
102 1.5 L 1921 Chateau Neuf du Pape 1,000
103 Ruby Slipper from Wizard of Oz 50,000
Bidders
BidderID LastName FirstName CreditLimit SSNO
1 Jones Rick 1,000 111-22-1111
2 Morris Gary 2,000,000 222-11-1111
3 Sussman David 25,000 333-33-8777
Bids
BidNumber ItemID BidderID Amount BidChannel
1 102 2 1,000 Phone
2 100 1 81 In Person
3 102 3 1,100 In Person
4 102 2 1,500 Phone
5 100 3 100 In Person
6 101 1 81 In Person
Now the problem that I am having is this. Here is the next set of instructions:
Write an SQL script which produces a query showing every single itemID, Description, Bidfloor, winning bid amount, winningBidNumber, winning bidder last name, and winning bidder first name. Your list should include items that were not bid on and should be in order from the lowest winning bid price to the highest winning bid price. Name your script winningbids.sql
I have it working except I don't know how to get the items that no one bids on. Heres my code for this part:
MySQL Syntax (Toggle Plain Text)
SELECT Items.itemID, description, bidfloor, amount as WinningBid, bidnumber, lastname, firstname FROM Items FULL OUTER JOIN (SELECT Bids.ItemID, max(amount) as WinningBid FROM Bids GROUP BY Bids.ItemID) newTable ON Items.ItemID = newTable.ItemID FULL OUTER JOIN Bids ON Items.ItemID = Bids.ItemID FULL OUTER JOIN Bidders ON Bidders.BidderID = Bids.BidderID WHERE amount = newTable.WinningBid ORDER BY amount;
Any advice is greatly appreciated.
Last edited by jared717; May 29th, 2009 at 10:57 am.
You seem to be getting mixed up with your joins.
You need to do an inner join to get the winning bids. I'd create this as a view:
I just typed this from memory so sorry about the table/column names
Then you can use a left join to join from items; the left join will mean that if an item doesn't have a winning bid it will show NULL.
You need to do an inner join to get the winning bids. I'd create this as a view:
I just typed this from memory so sorry about the table/column names

sql Syntax (Toggle Plain Text)
CREATE view winning bids as SELECT b1.* FROM bids b1 INNER JOIN ( SELECT b2.item_id, max(b2.amount) as amount FROM bids b2 GROUP BY b2.item_id ) b2 on b1.item_id = b2.item_id AND b1.amount = b2.amount;
Then you can use a left join to join from items; the left join will mean that if an item doesn't have a winning bid it will show NULL.
Note to self... pocket cup
![]() |
Similar Threads
- Need Microsoft SQL certified professional (Tech / IT Consultant Job Offers)
- SQL Server Developer, Manchester, UK (Software Development Job Offers)
- ASP.NET/SQL Developer/Programmer (Web Development Job Offers)
- Freelance .NET / MS SQL developer (Web Development Job Offers)
- Software Engineer (.NET , SQL) (Software Development Job Offers)
- UPS is Hiring!! PL/SQL & UNIX Technical Specialist (Software Development Job Offers)
- SQL Server DBA - " Hot " (Software Development Job Offers)
- PHP / My SQL Web developer (Web Development Job Offers)
- Sql Dba (Software Development Job Offers)
- SQL Server DBA (Software Development Job Offers)
Other Threads in the MySQL Forum
- Previous Thread: Suggestions plz?
- Next Thread: Connect to MySQL
| Thread Tools | Search this Thread |
agplv3 amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





