In Access I have four tables T1, T2, T3
and T4
, with Fields from 1 to 10. One of their field is "Field1" so that I have the followings:
[T1].Field1, [T2].Field1, [T3].Field1, [T4].Field1
I would like to select all the values for which at least one Field1 is equal.
In other words I would like to do something like
SELECT Field1,
Field2,
Field4,
Field5
FROM all the table before
WHERE [T1].Field1 = [T2].Field1
OR [T1].Field1 = [T3].Field1
OR [T1].Field1 = [T4].Field1
OR [T2].Field1 = [T3].Field1
OR [T2].Field1 = [T4].Field1
OR [T3].Field1 = [T4].Field1
-
My main difficulty is the FROM
part because SELECT
is fine and I can put there all the Fields I am interested in of the different tables, also the WHERE
should be fine because I can say as I reported above. The issue is in selecting the data with the FROM
command in Access. I believe it could be done with an Outer Join but I do not know how to implement it.
Suppose I have:
TABLE1
1 Field1: 0012
Field2: TEST
Field3: TEST3
2 Field1: 0010
Field2: TEST
Field3: TEST3
TABLE2
1 Field1: 0012
Field2: TEST2
Field3: TEST3
2 Field1: 0044
Field2: TEST
Field3: TEST3
TABLE3
1 Field1: 0012
Field2: TEST2
Field3: TEST3
2 Field1: 0044
Field2: TEST
Field3: TEST3
TABLE4
1 Field1: 0011
Field2: TEST2
Field3: TEST3
2 Field1: 0010
Field2: TEST
Field3: TEST3
3 Field1: 0044
Field2: TEST2
Field3: TEST3
At this point I would like to generate an output
TABLE1.Field1 TABLE2.Field1 TABLE3.Field1 TABLE4.Field1 TABLE1.Field2 TABLE2.Field2 TABLE3.Field2 TABLE4.Field2
In this case the first row will the one associated with Field1 0012:
0012 0012 0012 NULL TEST TEST2 TEST2 NULL
The second to 0010:
0010 NULL NULL 0010 TEST NULL NULL TEST
And so on. Could you help me formalizing my idea?
Thanks a lot