On Sep 20, 9:56 am, Luke <vieviu...@gmail.comwrote:
I have 3 tables (table1, table2, table3), all of them contain same
columns ( id, code, date1, date2, date3) and I need to get out by
'code' field all records that:
1. are in all 3 tables (this is easy - simple join query)
2. are in table 1 and table2, not in table3
3. are in table 1, not in table 2, not in table3
4. are in table 1 and not table2 but in table 3
and so forth for every table.. - all combinations... In effect which
would be 12 sets of records. How can I do that ? Can somebody throw me
an example ? Thanks in advance.
Luke
Access doesn't usually like outer joins on the product of inner joins.
To get around this just split it out into queries.
1. Seems like you have this one handled, but here it is anyway
SELECT table_1.ID
FROM (table_1 INNER JOIN table_2 ON table_1.ID = table_2.ID) INNER
JOIN table_3 ON table_2.ID = table_3.ID;
2. This one is a bit more complicated but will be the same for all
others like it.
select a.ID
from
(SELECT table_1.ID
FROM table_1 INNER JOIN table_2 ON table_1.ID = table_2.ID) as a left
outer join table_3 on a.id = table_3.id
where table_3.id is null
3. Simple outer join
SELECT table_1.ID
FROM table_3 RIGHT JOIN (table_1 LEFT JOIN table_2 ON table_1.ID =
table_2.ID) ON table_3.ID = table_1.ID
WHERE (((table_2.ID) Is Null) AND ((table_3.ID) Is Null));
Fun stuff, for a class?