tags:

views:

274

answers:

2

I have two tables that have the same structure; one contains permanaent data, and one is cleared and reset on a regular basis.

I need to make the same select statement work on both as if they were just one table

This is what I tried:

SELECT * FROM a,b WHERE 1;

Where a and b have the same structure;

+2  A: 

You may be looking at using a UNION in you query:

Select * from a
UNION
Select * from b

Note: It is better practice to qualify your column names instead of using the * reference. This would also make the query still useful if your two tables underwent schema changes but you still wanted to pull back all the data the two tables had in common.

TheTXI
Thanks the * was just the quickest way to test it out
Issac Kelly
A: 

So you want one set of results that contains the contents of both tables? If so then you'll need to do something like this:

select a.col1, a.col2 from a where...
UNION
select b.col1, b.col2 from b where...

mysql union syntax

Kevin Tighe