Combining results from two tables that share the same data structure

Posted on 2006-04-02
Last Modified: 2008-03-10
Suppose you have two tables: A and B. Both tables have the same columns: col1, col2, col3, etc.

So my records are distributed in two different tables that have the same format. I know, this is not good normalization design, but that is the way they are setup right now.

The question is: how do I query both in a single sql statement, combine the results of the query get all the records from both, and list the result in alphabetical order?

I can do:

select * from A ORDER BY status;

and I can also run:

select * from B ORDER BY status;

But how do I run both at the same time and get a single output from them?
Question by:cabrera48
    LVL 30

    Expert Comment

    (select * from A)
    (select * from B)
    ORDER BY status;
    LVL 30

    Accepted Solution

    Note also that if you are using MySQL 5.0, you can declare a VIEW that will combine the data from the two tables into a signle logical representation.

    Author Comment

    Great !!!

    That works !

    Thank you !
    LVL 30

    Expert Comment

    Good deal - thanks for the points!

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now