I've 3 MySQL tables:
** cities **
------------------
id name
------------------
1 New York
2 Los Angeles
3 San Francisco
...
** companies **
------------------
id name
------------------
1 Company 1 Ltd.
2 Company 2 Ltd.
3 Company 3 Ltd.
...
** city_companies **
-------------------------
id city_id company_id
-------------------------
1 2 3
2 1 2
3 3 3
4 3 2
5 1 1
For example with this query:
SELECT a.*, c.*
FROM cities a
INNER JOIN city_companies b ON a.id = b.city_id
INNER JOIN companies c ON b.company_id = c.id
WHERE a.city_id = '1'
This query will return the list of companies that belongs to 'New York' (specified in 'city_companies' table). I need to get opposite result - list of companies that doesn't belong to 'New York'.
Company 1 Ltd.thats in New Your as well???