SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Join Issue

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Join Issue

    Hey,

    I have 2 tables

    -companys-

    companyid
    accountid
    companyname

    and

    -pictures -

    pictureid
    accountid
    companyid
    picturename

    accountid is held as a session variable for the id of the user who submited the picture..

    I am trying to get only the company names where there is atleast one photo that holds the accountid

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try this SQL

    SELECT DISTINCT companyname FROM companys JOIN pictures USING (companyid);

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by _matrix_ View Post
    I am trying to get only the company names where there is atleast one photo that holds the accountid
    Code:
    SELECT companys.companyname
      FROM companys
    INNER
      JOIN pictures
        ON pictures.companyid = companys.companyid
       AND pictures.accountid = companys.accountid
    GROUP
        BY companys.companyname
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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