I have table definition like below:
- Place
(id, name) - Review
(id, userid, placeid) - Favorite
(id, userid, placeid) - Photo
(id, url, placeid)
whereplaceid
is foreign key to the id ofPlace
table.
On that table, I want to derive this kind of information:- placeid, place name, totalReview, totalFavorite, totalPhoto.
I got stucked. My progress currently I can derive information just from 1 table, like I can know totalReview of place, by using this mysql statement:
SELECT p.*, count(r.id) as totalReview from Place p left join Review r on p.id = r.placeid group by p.id
.
But, I don't know how I can derive the totalFavorite and totalPhoto.