I want to use the LEFT JOIN query to get some results from two tables with a one-to-many relationship, but limit the result set based on the count of children. I have two tables structured as:
customers
id name ...
1 "bob" ...
2 "jill" ...
orders
id customer_id ...
100 1 ...
101 2 ...
102 1 ...
(The rest of the data in the tables does not matter for this query.)
What I would like to do is get all the customer IDs and their order IDs, sorted by customer , but limited to the customers who placed several orders. . In this example, the results will look like this:
cust_id order_id
1 100
1 102
LEFT JOIN, , , , , , .
SELECT
`customers`.`id` AS `cust_id`,
`orders`.`id` AS `order_id`
FROM
`customers`
LEFT JOIN `orders` ON
`customers`.`id` = `orders`.`customer_id`
ORDER BY
`cust_id`
.