Jump to content

getting rows that dont exist


Canman2005

Recommended Posts

Hi all

 

I have the following statement

 

SELECT * FROM customers m INNER JOIN orders o ON m.id = o.customers_id

 

this gets all `customers` which have a row in the `orders` table

 

How can I alter this to get all `customers` which don't have a row existing in the `orders` table?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/139945-getting-rows-that-dont-exist/
Share on other sites

The following is not real code (obviously), but is how I'd try to make it work:

 

SELECT customer_id from orders

 

// php that puts all query results in an array

 

SELECT id from customers WHERE id NOT (in the array of customer who have orders)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.