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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:05:14+00:00 2026-05-15T01:05:14+00:00

If I have two tables in mysql that have similar columns… TABLEA id name

  • 0

If I have two tables in mysql that have similar columns…

TABLEA
  id
  name
  somefield1

TABLEB 
  id
  name
  somefield1
  somefield2

How do I structure a SELECT statement so that I can SELECT from both tables simultaneously, and have the result sets merged for the columns that are the same?

So for example, I am hoping to do something like…

SELECT name, somefield1 FROM TABLEA, TABLEB WHERE name="mooseburgers";

…and have the name, and somefield1 columns from both tables merged together in the result set.

Thank-you for your help!

Sample output appended because question unclear:

I want the rows from table1 and the rows from table2 appended in the resultset. For example if the tables contain

TABLEA
id(1) name(zoot) somefield(suit)

TABLEB
id(1) name(zoot) somefield(flute)

The resultet would look like:

name     |     somefield1
zoot           suit
zoot           flute
  • 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-15T01:05:15+00:00Added an answer on May 15, 2026 at 1:05 am

    You can combine columns from both tables using (id,name) as the joining criteria with:

    select
        a.id                               as id,
        a.name                             as name,
        a.somefield1 || ' ' || b.somefied1 as somefield1
    from tablea a, tableb b
    where a.id   = b.id
      and a.name = b.name
      and b.name = 'mooseburgers';
    

    If you want to join on just the (id) and combine the name and somefield1 columns:

    select
        a.id                               as id,
        a.name || ' ' || b.name            as name,
        a.somefield1 || ' ' || b.somefied1 as somefield1
    from tablea a, tableb b
    where a.id   = b.id
      and b.name = 'mooseburgers';
    

    Although I have to admit this is a rather unusual way of doing things. I assume you have your reasons however 🙂

    If I’ve misunderstood your question and you just want a more conventional union of the two tables, use something like:

    select id, name, somefield1, '' as somefield2 from tablea where name = 'mooseburgers'
    union all
    select id, name, somefield1, somefield2 from tableb where name = 'mooseburgers'
    

    This won’t combine rows but will instead just append the rows from the two queries. Use union on its own if you want to remove duplicate rows but, if you’re certain there are no duplicates or you don’t want them removed, union all is often more efficient.


    Based on your edit, the actual query would be:

    select name, somefield1 from tablea where name = 'zoot'
    union all
    select name, somefield1 from tableb where name = 'zoot'
    

    (or union if you don’t want duplicates where a.name==b.name=='zoot' and a.somefield1==b.somefield1).

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

Sidebar

Related Questions

I have two MySQL tables with a similar structure. i.e. Table_A - Col1, Col2,
I was thinking that I would have two tables for mysql. One for storing
I have two MySQL tables: attributes (attributeid, name) productsattributes (productid, attributeid, displayvalue) The required
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
I currently have two tables similar to users and programs that are linked through
In MySQL, is it possible to have a column in two different tables that
In MySql, I have two tables, A and B. A has as columns A.id,
I have a two mysql tables that I want to merge together in one
I have a question: I have two MSSQL tables, items and states, that are
I have two MySQL tables something like this: tool_owners: tool_owners_id | user_id | ...

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.