How to combine MySQL number of rows of the joined table, including 0?
I have two tables: 'company' and 'order'. The first one contains company
info and the second one holds all orders made with a company.
(order.company = company.ID).
I am making a query on the first table, for example all companies in the
city of New York. I would like to make a join with the order table, so
that it immediately shows how many orders for a company was made. I could
do this with a simple JOIN query, however, it does not include 0. For
example, if a company has no orders yet, it will not show up at all, while
it should be in the list with 0 orders.
Desired end result:
----------------------------------------
| ID | Name | ... | Orders |
----------------------------------------
| 105 | Company A | ... | 14 |
| 115 | Company B | ... | 5 |
| 120 | Company C | ... | 0 |
| 121 | Company D | ... | 0 |
----------------------------------------
Thanks in advance!
No comments:
Post a Comment