473,395 Members | 1,762 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,395 software developers and data experts.

INNER JOIN argument doubled?

Dear group!

The following statement gives me a resultset containing two columns
containing a PersonID:

SELECT *
FROM A
LEFT JOIN B ON A.PersonID=B.PersonID
UNION SELECT *
FROM A
RIGHT JOIN B ON A.PersonID=B.PersonID;

How can I change this statement to get only one PersonID that covers
the PersonIDs from A and B? I need this combined PersonID because I
have to combine that union with some more tables like this...

SELECT *
FROM D
LEFT JOIN Union_01 ON D.PersonID=Union_01.PersonID
UNION SELECT *
FROM D
RIGHT JOIN Union_01 ON D.PersonID=Union_01.PersonID;

And that only works with one PersonID, otherwise Access complains -
rightly!

Originally I wanted to combine five tables, also covering all
PersonIDs that only appear in some, but not in all tables, but I did
not find a way using Access (2003) - anyone got an idea?

SELECT A.*, B.*, D.*, R.*, T.*
FROM (((A INNER JOIN B ON A.Personen_ID=B.Personen_ID) INNER JOIN D ON
B.Personen_ID=D.Personen_ID) INNER JOIN R ON
D.Personen_ID=R.Personen_ID) INNER JOIN T ON
R.Personen_ID=T.Personen_ID
ORDER BY A.Personen_ID;

This is nice, but skips the mentioned entries where a Person_ID e.g.
only appears in table D :-(

Thank you very much!

With kind regrads,
Chriss

P.S: Originally, I had five Excel-Tables I wanted to combine... *sigh*

Feb 20 '07 #1
7 2547
Christian Muenscher wrote:
Dear group!

The following statement gives me a resultset containing two columns
containing a PersonID:

SELECT *
FROM A
LEFT JOIN B ON A.PersonID=B.PersonID
UNION SELECT *
FROM A
RIGHT JOIN B ON A.PersonID=B.PersonID;
[snipped]

Hi Chriss,

If you only want to see PersonID from one table try

SELECT A.*
FROM A
LEFT JOIN B ON A.PersonID=B.PersonID
UNION SELECT A.*
FROM A
RIGHT JOIN B ON A.PersonID=B.PersonID;

or, specify exactly which fields you want to see from A and/or B.

Hope this helps
--
Smartin
Feb 21 '07 #2
Hi Smartin!

On 21 Feb., 01:45, Smartin <smartin...@yahoo.comwrote:
If you only want to see PersonID from one table try

SELECT A.*
FROM A
LEFT JOIN B ON A.PersonID=B.PersonID
UNION SELECT A.*
FROM A
RIGHT JOIN B ON A.PersonID=B.PersonID;

or, specify exactly which fields you want to see from A and/or B.
Maybe I was not exact enough... I don't want to see only the PersonID
from one table, I want to see *all* PersonIDs, that means I want to
see the PersonIDs from table one plus the eventually additional
PersonIDs from table two plus the eventually additional PersonIDs from
table three plus... and so on. And I want to have only that one column
with PersonIDs for all tables. Difficult :(

Thanks for your help!

With kind regards,
Chriss

Feb 21 '07 #3
On Feb 21, 2:30 pm, "Christian Muenscher" <ccr...@gmail.comwrote:
Hi Smartin!

On 21 Feb., 01:45, Smartin <smartin...@yahoo.comwrote:
If you only want to see PersonID from one table try
SELECT A.*
FROM A
LEFT JOIN B ON A.PersonID=B.PersonID
UNION SELECT A.*
FROM A
RIGHT JOIN B ON A.PersonID=B.PersonID;
or, specify exactly which fields you want to see from A and/or B.

Maybe I was not exact enough... I don't want to see only the PersonID
from one table, I want to see *all* PersonIDs, that means I want to
see the PersonIDs from table one plus the eventually additional
PersonIDs from table two plus the eventually additional PersonIDs from
table three plus... and so on. And I want to have only that one column
with PersonIDs for all tables. Difficult :(

Thanks for your help!

With kind regards,
Chriss

If you want something that just works, I would do it this way. (I am
no expert, and may be that's why this occurs to me)

1. SELECT A.PersonID INTO tmpID FROM A; 'Creates a table tmpID

2. INSERT INTO tmpID ( PersonID ) 'Appends into tmpID
SELECT B.PersonID
FROM B;

do this for all the tables you want and then finally

SELECT DISTINCT tmpID.PersonID FROM tmpID; 'Get all the
unique IDs

After this you can delete the table tmpID.

There might be more efficient ways to do this. But this works.

HTH

Sunil Korah

Feb 21 '07 #4
Dear Sunil!

On 21 Feb., 14:50, "Sunil Korah" <kor...@gmail.comwrote:
There might be more efficient ways to do this. But this works.
Thanks, that works fine! But now I ran into a different problem... I
connected all seven table's PersonID to the PersonID of the temporary
table via an INNER JOIN. That selects all I want as long as the
PersonIDs are the same in all tables. But if I've got PersonID 1 to 5
in table 1, ID 6-10 in table 2, 11-15 in table 3 and so on (all
different) then I only get an empty result set. What will I have to do
here? Use a LEFT/RIGHT JOIN?

With kind regards,
Chriss

Feb 22 '07 #5
On Feb 22, 1:28 pm, "Christian Muenscher" <ccr...@gmail.comwrote:
Dear Sunil!

On 21 Feb., 14:50, "Sunil Korah" <kor...@gmail.comwrote:
There might be more efficient ways to do this. But this works.

Thanks, that works fine! But now I ran into a different problem... I
connected all seven table's PersonID to the PersonID of the temporary
table via an INNER JOIN. That selects all I want as long as the
PersonIDs are the same in all tables. But if I've got PersonID 1 to 5
in table 1, ID 6-10 in table 2, 11-15 in table 3 and so on (all
different) then I only get an empty result set. What will I have to do
here? Use a LEFT/RIGHT JOIN?

With kind regards,
Chriss

First of all, I was away in between and saw the post only now.

More importantly, I am not clear about what you mean. Which is 'the
temporary table' that you mention. I cant see any point in connecting
fields which do not have common values. It would be better if you can
explain what you are trying to achieve. What information are you
trying to get out of your tables?

Sunil Korah

Feb 27 '07 #6
Dear Sunil!

On 27 Feb., 18:03, "Sunil Korah" <kor...@gmail.comwrote:
More importantly, I am not clear about what you mean. Which is 'the
temporary table' that you mention. I cant see any point in connecting
fields which do not have common values. It would be better if you can
explain what you are trying to achieve. What information are you
trying to get out of your tables?
The temporary table I mentioned is the table tmpID you introduced some
posts earlier. I will try to explain my problem in detail:
Our students sometimes are having some kind of practical exams in
different sub-subjects. For each of these sub-subjects, I get one
table containing the results of that exam, this time there are seven
tables. The data is being created by scanning the rater forms using a
high-speed duplex document scanner, the Software "TeleForm" outputs
the results after a manual correction cycle. It is possible that some
students only take part in e.g. three of these exams. Now the
lecturers want me to deliver *one* table (best in Excel) containing
the accumulated results of all (seven in this case) exams. Here a
simplyfied example:

table 1:
StudentID Result1 Result2 Time (<< column titles)
0001 0 1 5
0002 1 1 4
0003 1 1 5
0004 1 1 5
0005 1 0 3

table 2:
StudentID Result3 Result4 Time
0001 1 1 4
0002 0 0 5
0003 1 0 3
0011 1 1 2
0015 1 1 5

table 3:
StudentID Result5 Result6 Time
0003 1 1 5
0004 0 1 4
0005 0 0 4
0011 1 1 5
0012 1 1 2

cumulative table:
StudentID Result1 Result2 Time_t1 Result3 Result4 Time_t2 Result5
Result6 Time_t3
0001 0 1 5 1 1 4
0002 1 1 4 0 0 5
0003 1 1 5 1 0 3 1 1 5
0004 1 1 5 0 1 4
0005 1 0 3 0 0 4
0011 1 1 2
0012 1 1 2
0015 1 1 5

The process of getting from the separate tables to the accumulated
table shouldn't be too complicated, because the lecturer or their
helpers should be able to do that by themselves using my step-by-step
instructions. If thats not possible it should at least be *easy and
fast* to use for my successor (Bachelor of Computer Science, I guess).
By "connecting" all tables using INNER JOIN (maybe via the Access
assistant) on the StudentID I get great results *as long as all
StudentIDs appear in any of the tables*. But evil woes if one student
is only in the third one...
I hope I got it all more clear now? Is there a way I overlooked to
achieve what I want?

Thanks a lot!

With kind regards,
Chriss

Feb 28 '07 #7
Christian Muenscher wrote:
Dear Sunil!

On 27 Feb., 18:03, "Sunil Korah" <kor...@gmail.comwrote:
>More importantly, I am not clear about what you mean. Which is 'the
temporary table' that you mention. I cant see any point in connecting
fields which do not have common values. It would be better if you can
explain what you are trying to achieve. What information are you
trying to get out of your tables?

The temporary table I mentioned is the table tmpID you introduced some
posts earlier. I will try to explain my problem in detail:
Our students sometimes are having some kind of practical exams in
different sub-subjects. For each of these sub-subjects, I get one
table containing the results of that exam, this time there are seven
tables. The data is being created by scanning the rater forms using a
high-speed duplex document scanner, the Software "TeleForm" outputs
the results after a manual correction cycle. It is possible that some
students only take part in e.g. three of these exams. Now the
lecturers want me to deliver *one* table (best in Excel) containing
the accumulated results of all (seven in this case) exams. Here a
simplyfied example:

table 1:
StudentID Result1 Result2 Time (<< column titles)
0001 0 1 5
0002 1 1 4
0003 1 1 5
0004 1 1 5
0005 1 0 3

table 2:
StudentID Result3 Result4 Time
0001 1 1 4
0002 0 0 5
0003 1 0 3
0011 1 1 2
0015 1 1 5

table 3:
StudentID Result5 Result6 Time
0003 1 1 5
0004 0 1 4
0005 0 0 4
0011 1 1 5
0012 1 1 2

cumulative table:
StudentID Result1 Result2 Time_t1 Result3 Result4 Time_t2 Result5
Result6 Time_t3
0001 0 1 5 1 1 4
0002 1 1 4 0 0 5
0003 1 1 5 1 0 3 1 1 5
0004 1 1 5 0 1 4
0005 1 0 3 0 0 4
0011 1 1 2
0012 1 1 2
0015 1 1 5

The process of getting from the separate tables to the accumulated
table shouldn't be too complicated, because the lecturer or their
helpers should be able to do that by themselves using my step-by-step
instructions. If thats not possible it should at least be *easy and
fast* to use for my successor (Bachelor of Computer Science, I guess).
By "connecting" all tables using INNER JOIN (maybe via the Access
assistant) on the StudentID I get great results *as long as all
StudentIDs appear in any of the tables*. But evil woes if one student
is only in the third one...
I hope I got it all more clear now? Is there a way I overlooked to
achieve what I want?

Thanks a lot!

With kind regards,
Chriss
Hi again, and PMFJI, but /why/ are you storing results in so many tables?

The question is not meant to be pejorative... If each student can have
1, 2, 3, ... 6 results, this is a perfect one to many relationship! One
table for students, one table for results. If you normalize your data
structure you can easily report who has what result.

--
Smartin
Mar 1 '07 #8

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

Similar topics

3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
1
by: teneesh | last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
11
by: YZXIA | last post by:
Is there any difference between explicit inner join and implicit inner join Example of an explicit inner join: SELECT * FROM employee INNER JOIN department ON employee.DepartmentID =...
2
by: MATTXtwo | last post by:
I have this store procedure to select data from table with join like this...SELECT tblPeribadi.Personel_No, tblPeribadi.Nama,tblCompany.Keterangan as Company_Code, tblPeribadi.Jawatan,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.