Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query to multiple tables 1

Status
Not open for further replies.

Perilous1

IS-IT--Management
Mar 10, 2005
171
US
I have an access DB with two identical tables and I'd like to be able to 'Select * From Table1 Where (date = sDate)'

And in the very same query also pull from the cloned table as 'Select * From Table2 Where (date = sDate)'

Using 'And' seems to just make it think its secondary criteria for pulling from the first table queried. I'm certain there is an easy way to make this work. Any help would be appreciated.
 
Though I can't see a reason why you'd need to do this, I'd use a UNION query in this instance e.g.
Code:
Select * From Table1 Where (date = sDate)
UNION ALL
Select * From Table2 Where (date = sDate)
This will only work if the structure of the data in both table is exactly the same (i.e. the columns have the same datatype). Using UNION ALL will return all the data from both queries, just using UNION will return only rows from the second query that don't appear in the first (by the sound of your case that would be zero records).

Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Andy said has it should be done already. just adding that you should never use "select *". always specify the fields you wish on your particular query, as otherwise a change to the table structure can mess up your queries big time



Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Thanks again, Harley. That did work though I wound up going a different direction in the end and didn't leave it in.

Fred, as a rule I only use 'Select *' on read-only queries. But, thanks for the validation and reminder. I need both as often as I can get them nowadays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top