473,788 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Pe rsonID
UNION SELECT *
FROM A
RIGHT JOIN B ON A.PersonID=B.Pe rsonID;

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=Unio n_01.PersonID
UNION SELECT *
FROM D
RIGHT JOIN Union_01 ON D.PersonID=Unio n_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 2571
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.Pe rsonID
UNION SELECT *
FROM A
RIGHT JOIN B ON A.PersonID=B.Pe rsonID;
[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.Pe rsonID
UNION SELECT A.*
FROM A
RIGHT JOIN B ON A.PersonID=B.Pe rsonID;

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...@yah oo.comwrote:
If you only want to see PersonID from one table try

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

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.c omwrote:
Hi Smartin!

On 21 Feb., 01:45, Smartin <smartin...@yah oo.comwrote:
If you only want to see PersonID from one table try
SELECT A.*
FROM A
LEFT JOIN B ON A.PersonID=B.Pe rsonID
UNION SELECT A.*
FROM A
RIGHT JOIN B ON A.PersonID=B.Pe rsonID;
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.c omwrote:
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.c omwrote:
Dear Sunil!

On 21 Feb., 14:50, "Sunil Korah" <kor...@gmail.c omwrote:
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.c omwrote:
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.c omwrote:
>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
3356
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 inner joins, as follows : SELECT DISTINCT upcards.id,statuskey.status,upcards.firstname,upcards.lastname,originkey.ori gin,associatekey.username,associatekey2.username,upcards.deleted FROM upcards,status,origins,associates INNER JOIN status...
3
6418
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, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
6
9316
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: tblEmployees empId -- EmpName -- EmpRole -- EmpManager -------....------------.... ---------....--------------- 1........ dan yella..........1..........2
52
6356
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
3
16507
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 all data from the separate tables is shown in a view (instead of the reference id's pointing to the separate tables...) I have some troubles formulating the SQL statement: I tried:
12
13191
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
4610
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 one starts and ends. can someone please help. here's the code from the developer. SELECT a.EvalRecNo, w1.q1, w2.q2, w3.q3, w4.q4, w5.q5, w6.comment FROM (SELECT DISTINCT u.EvalRecNo FROM dbo.UData AS u...
11
19973
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 = department.DepartmentID
2
4532
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, tblPeribadi.Taraf_Jawatan, tblGroup.Keterangan AS Kumpulan,tblPeribadi.Gred,tblBusiness_Area.Keterangan AS Business_Area,tblCost_Center.Keterangan AS Kod_Pusat_Kos, tblPeribadi.IC_Baru, tblPeribadi.IC_Lama, ...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.