Results 1 to 3 of 3
  1. #1
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419

    subquery within a SELECT statement, what is wrong?

    What is wrong with this code? I am trying to get the seller name and buyer's name.
    I can't do that, so logically the only thing that makes sense is to have a sub-query within a select statement. Thanks, please let me know.



    Code:
    SELECT bid.bidder, user.uname, 
    (SELECT user.uname FROM bid INNER JOIN user ON bid.seller = user.uid) as [SELLER's name], 
    bid.ITEMiid, bid.STARTtime, bid.BIDtime, bid.BIDprice
    
    FROM user INNER JOIN bid ON bid.bidder = user.uid
    I got an error message, at most one record can be returned by this sub-query.

    So let me explain, the user name is on the user table. and the seller and buy both are on the bid table, off course seller and buyer are always will be different,
    so I am trying to get the seller's name and buyer's name, and it looks like if I do a join, I can only either get the seller or the buyer's name and not both.

    So what I did is create a sub-query within a SELECT of another separate join but the error is " at most one record can be returned by this sub-query."
    Last edited by June7; 09-25-2013 at 09:50 PM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I think you need to include the user table in the query twice, one each joined to bidder and seller fields. Use the query builder and drag the user table into the builder window twice, create a link from each.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    419
    Ok thanks. :-)

    That works, although I don't like to use builder window to construct SQL because I think it can make you not a better SQL developer
    but since I haven't seen a code similar I'd rely on it and now I see how it is written, hope I'd to be able to write it out on my own next time.
    Code:
    SELECT bid.bidder, user.uname, user_1.uname, bid.iid, bid.STARTtime, bid.BIDtime, bid.BIDprice, auction.enddate, auction.endtime
    FROM ([user] INNER JOIN bid ON user.uid = bid.bidder) INNER JOIN [USER] AS USER_1 ON bid.seller = USER_1.uid

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Maybe subquery with IIF statement
    By tmcrouse in forum Queries
    Replies: 2
    Last Post: 01-25-2012, 12:43 PM
  2. Subquery and IIF statement
    By ksamaniego in forum Queries
    Replies: 1
    Last Post: 08-15-2011, 03:17 PM
  3. INSERT INTO ... SELECT Subquery
    By TheDeceived in forum Programming
    Replies: 1
    Last Post: 10-19-2010, 09:29 AM
  4. Replies: 4
    Last Post: 09-03-2010, 02:55 PM
  5. What is wrong with my SQL Select statement?
    By John2810 in forum Programming
    Replies: 2
    Last Post: 04-01-2010, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums