I have 12 mysql db table like table1, table2,….table12. each table has 200,000 records. each record includes country, user-type, package column. i want to get a statistic of above 3 column. to do it, first, i am creating array. then using the array, i am getting the stat data.
for ($i=1; $i<=12; $i++)
{
$query="SELECT `country`, `usertype`, `package` FROM `table$i`";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$country= $row['country'];
$usertype= $row['usertype'];
$package= $row['package'];
$stat_array[$country][$usertype][$package]= 1 + $stat_array[$country][$usertype][$package]
}
}
It take lot of time to get result. Is this a best way to get statistic? please advice me a good method. also, will this use more RAM memory. i need a way to get with less memory usage
Thanks in advance
12 queries? Just notice, that there is
UNIONcommand inSQL.Try out this: