I have two tables in my DB – products & orders. An order can only be of one kind of product.
Here’s the basic idea:

What I’m trying to do is a query that given a copmany_id returns all the products (from that company) that have less than 10 orders (including 0)
my query looks like this:
SELECT p.*
FROM product p,
order o
WHERE p.company_id =?
AND o.product_id = p.id
GROUP BY p.id
HAVING Count(o.id) < 10
ORDER BY p.id DESC
The query works fine for products which have 0 < orders but doesn’t return ones with 0 orders. What do I need to do to return them as well?
You’re
INNER JOININGyour two tables, which means that only those products are returned for which there is at least one order.You will need to
LEFT OUTER JOINthe order table:A left outer join will return every record on the left-hand side of the
JOINoperation at least once, regardless if there is a matching record to the right-hand side of theJOINoperation.