mysql select where count = 0

Posted by david parloir on Stack Overflow See other posts from Stack Overflow or by david parloir
Published on 2010-06-15T12:25:31Z Indexed on 2010/06/15 12:32 UTC
Read the original article Hit count: 185

Filed under:

Hi,
In my db, I have a "sales" table and a "sales_item". Sometimes, something goes wrong and the sale is recorded but not the sales item's.
So I'm trying to get the salesID from my table "sales" that haven't got any rows in the sales_item table.

Here's the mysql query I thought would work, but it doesn't:

SELECT s.*
FROM sales s NATURAL JOIN sales_item si
WHERE s.date like '" . ((isset($_GET['date'])) ? $_GET['date'] : date("Y-m-d")) . "%'
AND v.sales_id like '" . ((isset($_GET['shop'])) ? $_GET['shop'] : substr($_COOKIE['shop'], 0, 3)) ."%'
HAVING count(si.sales_item_id) = 0;

Any thoughts?

© Stack Overflow or respective owner

Related posts about mysql