This is a bit of a random question, and I’ve been doing this using multiple queries in MySQL and a small bit of PHP.
I have a MySQL query:
SELECT *
FROM (reviews LEFT JOIN orders ON reviews.orderid = orders.orderid)
LEFT JOIN customers ON orders.custid = customers.id
WHERE customers.email = '$email'
which returns all product reviews from a specific customer.
I would like to know structure a separate query which would return all of the customer’s orders which are not yet reviewed. That is, where there is no record in the reviews table for a particular orderid.
So…
SELECT *
FROM orders LEFT JOIN customers ON orders.custid = customers.id
WHERE customers.email = '$email'
… which will return all customer orders, but I then want to perhaps use another WHERE clause and a LEFT JOIN so that now only orderid’s with no corresponding review records are returned. I’ve been trying to find something that will do this for some time now without any luck. Nothing seems to do the job.
As stated above, I have managed to do this using a combination of PHP/MySQL, however, it isn’t very efficient, so I wondered if anyone had any suggestions?
Thanks in advance.
Ryan
… maybe