I've 2 tables: Clients and Orders. A person has numerous orders as well as an order goes to some customer. An order could be approved (marked with a area approved_at). I wish to retrieve all of the clients with no approved order. Including clients with no order and clients with orders that are not approved (approved_at = null). Can One do that in one query without subqueries?
SELECT ..., COUNT(Orders.id) AS cnt FROM Customers LEFT JOIN Orders ON (Customers.id = Orders.Customer_id) AND (Orders.approved_at is null) HAVING cnt = 0
SELECT c.* FROM Customers c LEFT JOIN Orders o ON c.ID = o.CustomerID WHERE o.ID IS NULL OR c.Approved_at IS NULL