Combining results from two tables that share the same data structure

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?
cabrera48Asked:
Who is Participating?
 
todd_farmerCommented:
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.
0
 
todd_farmerCommented:
(select * from A)
UNION
(select * from B)
ORDER BY status;
0
 
cabrera48Author Commented:
Great !!!

That works !

Thank you !
0
 
todd_farmerCommented:
Good deal - thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.