www.webdeveloper.com
Results 1 to 6 of 6

Thread: retreiving data from two tables

  1. #1
    Join Date
    Apr 2012
    Posts
    111

    retreiving data from two tables

    I am trying to retreive data from two tables. when I run it, it only shows the one file in documents, and not the other one in uploads.

    Code:
    Select *
    from uploads, documents 
    WHERE uploads.user = '$userID' AND documents.user = '$userID'
    ORDER BY uploads.title ASC, documents.title ASC

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Since MySQL is a relational database you need to indicate that relationship such as

    WHERE uploads.user = documents.user AND uploads.user = $userID

    are the titles also identical ?

    WHERE uploads.title = documents.title

    Your SELECT statement may need to be more specific too.

  3. #3
    Join Date
    Apr 2012
    Posts
    111
    What I have is two tables. one is general uploads (pictures, videos, etc.). the other one is of documents. i wanted to combine the two so that the user can see what they have.

  4. #4
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    Try this:

    Code:
    Select *
    from uploads left join documents on (uploads.user = documents.user)
    WHERE uploads.user = '$userID'
    ORDER BY uploads.title ASC, documents.title ASC

  5. #5
    Join Date
    Apr 2012
    Posts
    111
    i don't get anything then for this.

  6. #6
    Join Date
    Oct 2009
    Posts
    658
    Provide everyone with your current structure and what you want to extract from them. Our mind reading skills haven't been upgraded for a while

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles