I have 3 tables in mysql, one is customer, another store and reserve, this is related to the customer table and steals the id and the store tbl and also steals your id, my question is, how can I make a list of all the clients and know how many reservations do I have ?, since I may have many or none, and try with a count and only take into account the ones that have been booked, and I want everyone to take me into account, and that they did not do any in any case give me count 0, how could I control that?
customer table
store table
reservation table
I've tried this query:
SELECT c.Id_cliente, c.Nombre, COUNT(r.Id_reserva) as total
FROM cliente c
LEFT JOIN reserva r
ON c.Id_cliente = r.Id_cliente
GROUP BY c.Id_cliente
It works for me however, I forgot a detail, in the reservation table, I have a condition field that can be 1 or 0, it is 1 when they are valid and 0 when they end, when doing a where so that only I take in account the current reserves no longer works my query.