mysql - Joining 3 tables and count different fields -


i have query in loop through itemlist(alerts), these alerts have replies want know how many replies alert/item has, these alerts/items have sort of like(interaction) button want know how many people liked it, have query gives me how many replies have, don't know how can count how many interactions has... take @ , maybe me ?

this query far:

select a.title, a.lat, a.lon, a.alert_content_id, a.date_added, count(*) `alerts`     left join `reply` r on         r.alert_id = a.alerts     left join `interactions` on        i.alert_id = a.alerts     group a.title, a.lat, a.lon, a.alert_content_id, a.date_added 

now count returns number of replies, how can count number of interactions well? desired result

|a.title|a.lat|a.lon|a.alert_content_id|a.date_added|count(replies)|count(interactions)| 

count replies number of rows a.alerts == r.alert_id , count interactions number of rows a.alerts == i.alert_id

so after bit more fidling found answer, returned needed.

select a.title, a.lat, a.lon, a.alert_content_id, a.date_added, count(r.alert_id) countrep ,count(i.alert_id) countint  `alerts`        left join `reply` r on           r.alert_id = a.alerts        left join `interactions` on           i.alert_id = a.alerts  group a.title, a.lat, a.lon, a.alert_content_id, a.date_added 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -