I have problems with a query that involves three tables.
Table contacts: contact_id, contact_name
Table companies: company_id, company_name
Table ref_company_contacts: ref_id, contact_id, company_id
If i want to get contacts for a company the query goes like this:
$companyId = 3;
$sql = "SELECT contacts.* FROM contacts, companies, ref_company_contacts";
$sql.= " WHERE companies.company_id = '$companyId'";
$sql.= " AND companies.company_id = ref_company_contacts.company_id";
$sql.= " AND ref_company_contacts.contact_id = contacts.contact_id";
But what shall i do if i want to select only the contacts in table "contacts" that not have a referanse to the company in table "ref_company_contacts".
Hope someone can help me.