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

Try this SQL

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

SELECT companys.companyname
  FROM companys
INNER
  JOIN pictures
    ON pictures.companyid = companys.companyid
   AND pictures.accountid = companys.accountid
GROUP
    BY companys.companyname