943,865 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 598
  • MySQL RSS
May 29th, 2009
0

SQL Help!!!

Expand Post »
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:

MySQL Syntax (Toggle Plain Text)
  1. SELECT Items.itemID, description, bidfloor, amount as WinningBid, bidnumber, lastname, firstname
  2. FROM Items FULL OUTER JOIN (SELECT Bids.ItemID, max(amount) as WinningBid
  3. FROM Bids
  4. GROUP BY Bids.ItemID) newTable
  5. ON Items.ItemID = newTable.ItemID
  6. FULL OUTER JOIN Bids ON Items.ItemID = Bids.ItemID
  7. FULL OUTER JOIN Bidders ON Bidders.BidderID = Bids.BidderID
  8. WHERE amount = newTable.WinningBid
  9. ORDER BY amount;

Any advice is greatly appreciated.
Last edited by jared717; May 29th, 2009 at 10:57 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jared717 is offline Offline
3 posts
since Feb 2009
May 29th, 2009
0

Re: SQL Help!!!

Try to repost your select statement between tags because I cannot even seen it.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
432 posts
since May 2009
May 29th, 2009
0

Re: SQL Help!!!

Thanks, I just fixed the code
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jared717 is offline Offline
3 posts
since Feb 2009
May 29th, 2009
0

Re: SQL Help!!!

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

sql Syntax (Toggle Plain Text)
  1. CREATE view winning bids as
  2. SELECT b1.*
  3. FROM bids b1
  4. INNER JOIN (
  5. SELECT b2.item_id,
  6. max(b2.amount) as amount
  7. FROM bids b2
  8. GROUP BY b2.item_id
  9. ) b2
  10. on b1.item_id = b2.item_id
  11. 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.
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Suggestions plz?
Next Thread in MySQL Forum Timeline: Connect to MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC