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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:50:11+00:00 2026-05-23T13:50:11+00:00

I am trying to select from 2 databases on the same server that have

  • 0

I am trying to select from 2 databases on the same server that have the exact same structure and db2 is a continuance of db1. The problem is I am trying to select the same info "different unique id’s though" from both databases and I need the query formatted as such: link_id AS id, title AS title to present the info correctly using $row['title'] etc. Here is my query:

$CONF['mysql_query'] = 'SELECT db1.l.link_id AS id, db1.l.title AS title, db2.r.link_id AS id, db2.r.title AS title FROM db1.links AS l LEFT OUTER JOIN db2.links AS r ON (r.link_id = l.link_id) WHERE l.link_id IN ($ids)';

Why will it not allow me to use title AS title etc for both databases? Is there a way I can do this?

  • 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-05-23T13:50:12+00:00Added an answer on May 23, 2026 at 1:50 pm

    You can’t have 2 columns with same name in a SELECT list. That’s why you can’t have two id or two title.

    If you want to join the two tables, use:

    $CONF['mysql_query'] = "
            SELECT l.link_id AS idL
                 , l.title AS titleL
                 , r.link_id AS idR
                 , r.title AS titleR
            FROM db1.links AS l
              LEFT OUTER JOIN db2.links AS r
                ON (r.link_id = l.link_id)
            WHERE l.link_id IN ($ids)
        ";
    

    The above will show all ids and titles that satisfy the l.link_id IN ($ids) condition from the first table and the corresponding title from the second table. NULLs in the 3rd and 4th column will show if there is no corresponding row in the second table.


    If you want a UNION, e.g. all rows from the first table (that satisfy the l.link_id IN ($ids) condition) plus all rows from the second table, use:

    $CONF['mysql_query'] = "
            SELECT link_id AS id
                 , title AS title
            FROM db1.links AS l
            WHERE l.link_id IN ($ids)
        UNION                   
            SELECT link_id AS id
                 , title AS title
            FROM db2.links AS r
        ";
    

    This will possibly show rows with same id, one from each table. Or even duplicate rows. Duplicate rows can be avoided easily though, by putting UNION ALL instead of UNION.

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

Sidebar

Related Questions

I'm running into a problem when trying to select records from my 2005 MS-SQL
I have a SQL Server that houses Several Databases. I have a Main Database
I’m trying to select various table and column names from a (SQL Server 2008)
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying to SELECT based on a date in OpenOffice Base: SELECT * FROM
I'm trying to select records with a statement SELECT * FROM A WHERE LEFT(B,
I'm trying to select data from a table defined similar to the following :
I am trying to select data from two tables and insert it into another
I am trying to select rows from a table where one of the (NVARCHAR)
Well, I was trying to select rows from one table if there are no

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.