We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Combining results from two tables that share the same data structure

cabrera48
cabrera48 asked
on
Medium Priority
309 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?
Comment
Watch Question

Top Expert 2006

Commented:
(select * from A)
UNION
(select * from B)
ORDER BY status;
Top Expert 2006
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Great !!!

That works !

Thank you !
Top Expert 2006

Commented:
Good deal - thanks for the points!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.