473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

3 tables, join query question


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

Sep 20 '07 #1
1 4840
Ben
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?

Sep 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
0
by: Richard Bolen | last post by:
I'm trying to write a select query that involves 2 tables. One table (Submissions) has a one to many relationship with the other table (Jobs). I'm trying to find all the records in Jobs that do...
0
by: Swartz | last post by:
Hi all. I'm trying to write a query but cant get it to work right. I have two tables that I wish to join table: required_books Columns: class_id, isbn ---------------- x | 1
1
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
3
by: MX1 | last post by:
Here's a simple query question. I have tables. One is an order table and one is an order detail table. tOrder tOrderDetail The tOrder table contains basic info like customer name, date, a...
4
by: Shahzad | last post by:
dear respected gurus, I would like to knew how to apply append,insert query for a self table where no primary keys issues. i do have problem say there are 5 rows of single record, this is data...
5
by: Scott Frankel | last post by:
How does one embed a sub-query lookup to one table in order to replace a foreign key id number with it's name in a SELECT on a second table? i.e.: given the following two tables, I want to...
2
by: Grip | last post by:
Just started teaching myself Access and I've got a newbie question... I have two tables tblPpl and tblOrgs linked by a many-to-one relationship. I'm trying to produce a report that will show a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.