?
Solved

Combining results from two tables that share the same data structure

Posted on 2006-04-02
4
Medium Priority
?
285 Views
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?
0
Comment
Question by:cabrera48
  • 3
4 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 16356734
(select * from A)
UNION
(select * from B)
ORDER BY status;
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 1000 total points
ID: 16356737
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
 

Author Comment

by:cabrera48
ID: 16357993
Great !!!

That works !

Thank you !
0
 
LVL 30

Expert Comment

by:todd_farmer
ID: 16361496
Good deal - thanks for the points!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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