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

  • Home
  • SEARCH
  • 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 8308363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:47:18+00:00 2026-06-08T18:47:18+00:00

I have 2 databases on the same server with 2 identical tables. What I

  • 0

I have 2 databases on the same server with 2 identical tables.

What I want to do is select all records from both tables and join them in one array.
I’ve been messing around with the script below. For some reason it returns the records of db2.tbl twice and doesn’t return the db1.tbl records at all. When I try to select the data from a single database is works fine for both of them. Does any one see the problem?

<?PHP
 require_once("config.php");

$conn = @mysql_connect($dbhost, $dbuser, $dbpass)or die ('Error connecting to mysql server'.mysql_error());
$q = mysql_query("SELECT * FROM db1.tbl JOIN db2.tbl");
var_dump(mysql_num_rows($q));
while($arr = mysql_fetch_assoc($q)){
    var_dump($arr);
}

?>
  • 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-08T18:47:19+00:00Added an answer on June 8, 2026 at 6:47 pm

    Is this what you want ? All records from database1 followed by all records from database2:

    $q = mysql_query("SELECT * FROM db1.tbl UNION SELECT * FROM db2.tbl"); 
    

    I assume the user you are connecting with has access to both databases.

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

Sidebar

Related Questions

I have to tables in different databases (on the same server) that are identical.
I have nine different databases representing companies, all on the same SQL server 2008
I have two SQL Server (2000) databases. Both are used for the same project,
I have 2 databases with same tables. DBProduction and DBLocal both have testTable. How
I have 2 identical tables in 2 different databases that reside on the same
I have two identical databases on the same server. During a deployment process, I
I have 2 databases on the same SQL Server. Is it possible to have
I have several databases (SqlServer 2005) on the same server with the same schema
I have two databases at two different places, both databases are same with table
I have 2 seperate databases with the same structure. I want to move a

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.