I have two tables, one contains customers, the other one the bookings.
Now i want to see how many bookings come from one person but display it with their name instead of the id.
SELECT booking.id, COUNT(booking.id) AS idcount
FROM booking
GROUP BY booking.id ORDER BY idcount DESC;
The output is (correct count):
id | idcount
----------+--------
2 | 8
1 | 4
My attempt at getting the name displayed instead of the id was:
SELECT customer.lastn, customer.firstn, COUNT(booking.id) AS idcount
FROM booking, customer
GROUP BY customer.lastn, customer.firstn ORDER BY idcount DESC;
The output (wrong count):
lastn | firstn | idcount
----------+---------+--------
Adam | Michael | 13
Jackson | Leo | 13
13 is the total number of bookings (i just cut the output off) so there's that coming from, however i cant make the transition to get the right count with the name.