Forum Moderators: open

Message Too Old, No Replies

mysql JOIN

         

bilenkyj

10:55 am on Apr 28, 2008 (gmt 0)

10+ Year Member



Hi Guys, another join query, i cant get my head around.
I have 2 tables, one is company, the other is connectors.

i want a list of companies that are present in company table but no in connectors.

table company
company_name

table connectors
company_name
connector_name

I need results that list companies that do not appear at all in connectors either the company_name or connector_name columns.

I have no idea how to do this and display the results, typical format i use is

$restofcompanylist=mysql_query("SELECT*FROM company LEFT JOIN connectors ON company.company_name=connectors.company_name WHERE (connectors.company_name) IS NULL");

the use a while loop to display results

while($restcompanyresults=mysql_fetch_array($restofcompanylist)){
echo"".$restcompanyresults['connectors.company_name']
}

Im stuck as my query above shows me nothing and its also only checking is the company name is in the company name column, it may only be in the connector_name column in which case the company is in the table and shouldnt be displays in my results, can anyone please help?

Demaestro

2:17 pm on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



("SELECT*FROM company LEFT JOIN connectors ON company.company_name=connectors.company_name WHERE (connectors.company_name) IS NULL");

The part I have marked bold is saying that the name has to be NULL, which means has no value.

Take that out and try it...

("SELECT*FROM company LEFT JOIN connectors ON company.company_name=connectors.company_name");

bilenkyj

2:21 pm on Apr 28, 2008 (gmt 0)

10+ Year Member



i got it with this in the end

$query = "SELECT company_name FROM company WHERE company_name NOT IN (SELECT company_name FROM connectors UNION SELECT connector_name FROM connectors UNION SELECT company_name FROM enablement)";

thanks for your help