Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:00:44+00:00 2026-06-15T06:00:44+00:00

I have 12 mysql db table like table1, table2,….table12. each table has 200,000 records.

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:00:46+00:00Added an answer on June 15, 2026 at 6:00 am

    12 queries? Just notice, that there is UNION command in SQL.
    Try out this:

    for ($i=1; $i<=12; $i++)
       $query=($i>1?'UNION ALL ':'')."SELECT `country`, `usertype`, `package` FROM `table$i` ";
    $result=mysql_query($query);
    // other code below
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a table like, Table1(Contract_id, name, address, contact_no) and another table like, Table2(Contract_id,
I have a MySQL table like so; foo bar 1 21 23 17 31
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (sorted
I have a MySQL table like id | text | category | active I
I currently have a MySQL table like: id | friend 1 | 2 1
I have a mysql table structure like that: id int primary key name varchar
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field
I have a MySQL table and would like to return the rows based on
I have a mysql table that looks like this: id col2 col3 col4 1
I have a MySQL table structured somewhat like this: type name value ===================== 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.