multiple table query

  • Thread starter Thread starter jdeming
  • Start date Start date
J

jdeming

Guest
Hello,
Could someone tell me how to combine the following three statements into one and still get the same results returned.

SELECT column1,column2,column3 FROM tbl1987 WHERE column1 =1234;

SELECT column1,column2,column3 FROM tbl1988 WHERE column1 =1234;

SELECT column1,column2,column3 FROM tbl1989 WHERE column1 =1234;

SELECT column1,column2,column3 FROM tbl1990 WHERE column1 =1234;

The value 1234 may or may not be found in all of the tables. I hope this is clear. Thanks in advance.

Justin
 
With the possibility of any of your four queries pulling no data, you can't pick any of the tables as the "base" table and running a series of left joins to the other tables within one select query.

Look up up in Help info on how to write a union query, it isn't too difficult. Each contributing query must contain the same number of fields with the matching datatypes of the corresponding fields.
 
AsGlynch told before, use a UNION:

SELECT column1,column2,column3 FROM tbl1987 WHERE column1 =1234
UNION
SELECT column1,column2,column3 FROM tbl1988 WHERE column1 =1234
UNION
SELECT column1,column2,column3 FROM tbl1989 WHERE column1 =1234
UNION
SELECT column1,column2,column3 FROM tbl1990 WHERE column1 =1234;

A remark off topic:

Why are you using different tables for each year. You'd better use one....
Now most certaibly you're dealing with a non-properly normalized database...

RV
 
To continue in that vein, combine all of those separate "yearly" tables into one table, add the field "fldYear", then write basically the same simple select query you have in your first post and group by the year field.
 

Users who are viewing this thread

Back
Top Bottom