Selecting data from two MySQL tables at once in php -
what have tried achieve;
counting number of rows in 2 tables (adding them together) grouping them country code in country
column in table. output results number of rows , country e.g.
- gb => 200 views
- us => 500 views
- ch => 119 views
mysql code have far;
select count(id) totalclicks, country adverts_analytics_user_clicks advertid =:advertid group country
this works well, need select same data table @ same time , combine count()
values according country
field.
any appreciated!
repeat first query against second table, such output coumns have same name , datatype.
then union results together.
finally sum total clicks country.
select country, sum(totalclicks) totalclicks ( select count(id) totalclicks, country adverts_analytics_user_clicks advertid =:advertid group country union select count(id) totalclicks, country table 2 advertid =:advertid group country ) group country
Comments
Post a Comment