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 8330299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:05:00+00:00 2026-06-09T02:05:00+00:00

I want to fetch datas from multiple identical tables (three and even more), they

  • 0

I want to fetch datas from multiple identical tables (three and even more), they got the same columns names (but different datas in the rows).

So, I want to fetch with loops all the tables as if it was one query (one loop), not three.

I do not want to triple the number of columns when fetching the array. I want all the tables to use the same columns names. The datas of the tables will be stacked one over the other in the array, not one next to the other, tripling the number of columns in the array. But, once they get stacked one over the other, the “ORDER BY” filter will “blend” the tables : the “ORDER BY” will act on all the tables at once (like if it was only one table), not on all the tables individually.

My query for 1 table looks like this :

$pdo = "SELECT * FROM " .$table1 ." ORDER BY price LIMIT " 
       .$current_page_offset .", " .$items_per_pages;

So…I want to fetch the three tables like if I was fetching only one.

*also want to keep my limit and “ORDER BY” even more filters working. I do not want a triple-limit showing three times the number of items i want on my page…

Is there a way to do that ?

*EDIT : I changed my description of “blended” at 3rd paragraph. sorry for (maybe) my bad English.

  • 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-09T02:05:01+00:00Added an answer on June 9, 2026 at 2:05 am

    You want to use UNION:

    UNION is used to combine the result from multiple SELECT statements into a single result set.

    Therefore, if your table names are in an array called $tables:

    mb_regex_encoding($charset); // character set of database connection
    foreach ($tables as $table) {
      $table = '`'.mb_ereg_replace('`','``',$table).'`';
      $sql[] = "(
        SELECT   *
        FROM     $table
        ORDER BY price
        LIMIT    $current_page_offset, $items_per_pages
      )";
    }
    $sql = implode(' UNION ALL ', $sql);
    

    However it sounds as though your schema should be normalised, such that you don’t have such “identical” tables: instead have a single table with an additional column to indicate whatever distinguishes each.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch data from three tables that are Products , Attributes and
hey guys i want to fetch 3 tables in 1 single ado.net call from
When I'm selecting from multiple tables that share column names is there a way
In asp.net(C#) i want to fetch data from a database using a stored procedure
I want write a simple query which will fetch data from a table (which
want to fetch the value from dynamically created textfield with tag from NSMutableArray.... Txt_New_Estimated
I want to fetch the title from book table and the subject name from
I want to fetch the unmatching records from two table in SQL, the table
I am trying to access Facebook from Python :D I want to fetch some
I have a search form field that I want to compare with multiple columns

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.