SQL Help!!!

Reply

Join Date: Feb 2009
Posts: 3
Reputation: jared717 is an unknown quantity at this point 
Solved Threads: 0
jared717 jared717 is offline Offline
Newbie Poster

SQL Help!!!

 
0
  #1
May 29th, 2009
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 185
Reputation: jbisono is an unknown quantity at this point 
Solved Threads: 24
jbisono's Avatar
jbisono jbisono is offline Offline
Junior Poster

Re: SQL Help!!!

 
0
  #2
May 29th, 2009
Try to repost your select statement between tags because I cannot even seen it.
If your already resolved your issue, flag it as solved.
José Bisonó
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3
Reputation: jared717 is an unknown quantity at this point 
Solved Threads: 0
jared717 jared717 is offline Offline
Newbie Poster

Re: SQL Help!!!

 
0
  #3
May 29th, 2009
Thanks, I just fixed the code
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 521
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: SQL Help!!!

 
0
  #4
May 29th, 2009
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

  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.
Note to self... pocket cup
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC