dbTalk Databases Forums  

ISO: sql technique to select information from more than one table

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss ISO: sql technique to select information from more than one table in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Larry W. Virden
 
Posts: n/a

Default ISO: sql technique to select information from more than one table - 03-09-2009 , 12:37 PM






I have the following set of tables and columns

T1:
Key1
Name
Dept.

T2:
Key2
Name
Dept

T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept

T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)

T4 maps the keys from one set of data to another. There should be rows
containing all the keys.

T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.

For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.

If the person's key is in t2, but no name is listed, I want to find
that as well.

I tried something to the effect of

select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
)

however, the resulting column values are not what I am expected.

I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.

Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.

Reply With Quote
  #2  
Old   
Shakespeare
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-09-2009 , 03:01 PM






Larry W. Virden schreef:
Quote:
I have the following set of tables and columns

T1:
Key1
Name
Dept.

T2:
Key2
Name
Dept

T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept

T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)

T4 maps the keys from one set of data to another. There should be rows
containing all the keys.

T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.

For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.

If the person's key is in t2, but no name is listed, I want to find
that as well.

I tried something to the effect of

select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
)

however, the resulting column values are not what I am expected.

I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.

Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.
Just did some quick reading of ypur post, but does this do what you ask?

Select 't2' source, t4.key0, ... some values here...
from t1,t2,t4
where t1.id=t4.key1 and t2.id=t4.key3
and t1.name <> nvl(t2.name,'xxx')
union 't3' source, t4.key0, etc..
from t1,t3,t4
where t1.id=t4.key1 and t3.id=t4.key3 and
t1.name <> nvl(t3.name,'xxx')

If not having an name in t2 or t3 means t2, t3.name is null you have to
take that into account as well, that's why the nvl(...'xxx') is there
(supposing no one is called 'xxx' of course)

Shakespeare



Reply With Quote
  #3  
Old   
Larry W. Virden
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 08:34 AM



On Mar 9, 5:01*pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Quote:
Larry W. Virden schreef:





I have the following set of tables and columns

T1:
Key1
Name
Dept.

T2:
Key2
Name
Dept

T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept

T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)

T4 maps the keys from one set of data to another. There should be rows
containing all the keys.

T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.

For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.

If the person's key is in t2, but no name is listed, I want to find
that as well.

I tried something to the effect of

select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
* * * * * *( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
* * * * * * *(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
* * * * * )

however, the resulting column values are not what I am expected.

I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.

Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.

Just did some quick reading of ypur post, but does this do what you ask?

Select 't2' source, t4.key0, ... some values here...
from t1,t2,t4
where t1.id=t4.key1 and t2.id=t4.key3
and t1.name <> nvl(t2.name,'xxx')
union 't3' source, t4.key0, etc..
from t1,t3,t4
where t1.id=t4.key1 and t3.id=t4.key3 and
t1.name <> nvl(t3.name,'xxx')

If not having an name in t2 or t3 means t2, t3.name is null you have to
take that into account as well, that's why the nvl(...'xxx') is there
(supposing no one is called 'xxx' of course)

Shakespeare- Hide quoted text -

- Show quoted text -
From an email

Quote:
Thank you so much for your suggestion. I really appreciate you taking
the time to post a reply.

When I take your suggestion and plug in my information, oracle sqlplus
seems to not like the suggestion, but doesn't
produce a message saying why.

SQL*Plus: Release 10.2.0.2.0 - Production on Tue Mar 10 10:11:18 2009

Copyright (c) 1982, 2005, Oracle. All Rights Reserved.

Quote:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit
Production
With the Partitioning and Data Mining options

1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials, csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')
10 union 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 csi_hr.first_name <> nvl(csi_telecom.first_name,'Not Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not Avail')

SQL

I can't see any obvious problem with my syntax, though I likely did
mess something up.

---
Quote:
What error do you get?

I think you should put the part

csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')

within parentheses in both parts of your query

Quote:
and there should be 'select' after the union (which I did forget too)

Shakespeare

ps Please respond in the newsgroup, in stead of mailing directly, so others can participate!
Sorry - I will respond here as requested.

1. I don't actually get an error - sqlplus just sits there as if it
did what I asked.

So, I made the changes you suggested, and sqlplus continues to
indicate that it has read the select, but provides no indication that
it has executed it or if there is an error, what the error is:

1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials,
csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 (csi_hr.first_name <> nvl(csi_security.first_name,'Not
Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not
Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not
Avail') )
10 union select 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 (csi_hr.first_name <> nvl(csi_telecom.first_name,'Not
Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not
Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not
Avail') )
SQL>


Reply With Quote
  #4  
Old   
Larry W. Virden
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 09:04 AM



Okay, here's the next thing that I have learned. I tried taking the
pieces of the select individually and executing them. When I did this,
the first select produces output. However, the second part of the
statement just stoped . interestingly enough, if I then type a / ,
the select occurs. So, I tried this version of my select, which I
tweaked to handle an issue with upper and lower case.

select 'csi_security' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_security.first_name, csi_security.initials,
csi_security.last_name
from csi_hr,csi_security,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_security.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_security.first_name,'NOT
AVAIL')
or upper(nvl(csi_hr.middle_name,'NOT AVAIL')) <> nvl
(csi_security.initials,'NOT AVAIL')
or upper(csi_hr.last_name) <> nvl(csi_security.last_name,'NOT
AVAIL') )
union select 'csi_telecom' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
from csi_hr,csi_telecom,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_telecom.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_telecom.first_name,'NOT
AVAIL') or
upper(nvl(csi_hr.middle_name,'NOT AVAIL')) <>
nvl(csi_telecom.middle_name,'NOT AVAIL') or
upper(csi_hr.last_name) <> nvl(csi_telecom.last_name,'Not
Avail') )

;

sqlplus reads the above query and doesn't execute it. Then I type a /
and it does execute it.

This brings me much closer to my desired output, even if I do have to
mess around a bit in the sql script file.

The one thing that would be ideal is if I could 'merge' the outputs so
that instead of 2 reports, one after the other, I got
one report, with the 3 sets of names on one line.

I had expected that the union would do that.

Reply With Quote
  #5  
Old   
Shakespeare
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 09:58 AM



Larry W. Virden schreef:
Quote:
On Mar 9, 5:01 pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Larry W. Virden schreef:





I have the following set of tables and columns
T1:
Key1
Name
Dept.
T2:
Key2
Name
Dept
T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept
T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)
T4 maps the keys from one set of data to another. There should be rows
containing all the keys.
T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.
For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.
If the person's key is in t2, but no name is listed, I want to find
that as well.
I tried something to the effect of
select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
)
however, the resulting column values are not what I am expected.
I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.
Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.
Just did some quick reading of ypur post, but does this do what you ask?

Select 't2' source, t4.key0, ... some values here...
from t1,t2,t4
where t1.id=t4.key1 and t2.id=t4.key3
and t1.name <> nvl(t2.name,'xxx')
union 't3' source, t4.key0, etc..
from t1,t3,t4
where t1.id=t4.key1 and t3.id=t4.key3 and
t1.name <> nvl(t3.name,'xxx')

If not having an name in t2 or t3 means t2, t3.name is null you have to
take that into account as well, that's why the nvl(...'xxx') is there
(supposing no one is called 'xxx' of course)

Shakespeare- Hide quoted text -

- Show quoted text -

From an email

Thank you so much for your suggestion. I really appreciate you taking
the time to post a reply.

When I take your suggestion and plug in my information, oracle sqlplus
seems to not like the suggestion, but doesn't
produce a message saying why.

SQL*Plus: Release 10.2.0.2.0 - Production on Tue Mar 10 10:11:18 2009

Copyright (c) 1982, 2005, Oracle. All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit
Production
With the Partitioning and Data Mining options

1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials, csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')
10 union 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 csi_hr.first_name <> nvl(csi_telecom.first_name,'Not Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not Avail')

SQL

I can't see any obvious problem with my syntax, though I likely did
mess something up.


---
What error do you get?

I think you should put the part

csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')

within parentheses in both parts of your query


and there should be 'select' after the union (which I did forget too)

Shakespeare

ps Please respond in the newsgroup, in stead of mailing directly, so others can participate!

Sorry - I will respond here as requested.

1. I don't actually get an error - sqlplus just sits there as if it
did what I asked.

So, I made the changes you suggested, and sqlplus continues to
indicate that it has read the select, but provides no indication that
it has executed it or if there is an error, what the error is:

1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials,
csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 (csi_hr.first_name <> nvl(csi_security.first_name,'Not
Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not
Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not
Avail') )
10 union select 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 (csi_hr.first_name <> nvl(csi_telecom.first_name,'Not
Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not
Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not
Avail') )
SQL
Maybe you can post the outcome of this query here?

select 'csi_security' source,
csi_hr.first_name,
csi_hr.middle_name,
csi_hr.last_name,
csi_security.first_name,
csi_security.initials,
csi_security.last_name
from csi_hr,csi_security,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_security.person_id=csi_core.sec_person_id

Shakespeare


Reply With Quote
  #6  
Old   
Shakespeare
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 10:19 AM



Larry W. Virden schreef:
Quote:
Okay, here's the next thing that I have learned. I tried taking the
pieces of the select individually and executing them. When I did this,
the first select produces output. However, the second part of the
statement just stoped . interestingly enough, if I then type a / ,
the select occurs. So, I tried this version of my select, which I
tweaked to handle an issue with upper and lower case.

select 'csi_security' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_security.first_name, csi_security.initials,
csi_security.last_name
from csi_hr,csi_security,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_security.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_security.first_name,'NOT
AVAIL')
or upper(nvl(csi_hr.middle_name,'NOT AVAIL')) <> nvl
(csi_security.initials,'NOT AVAIL')
or upper(csi_hr.last_name) <> nvl(csi_security.last_name,'NOT
AVAIL') )
union select 'csi_telecom' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
from csi_hr,csi_telecom,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_telecom.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_telecom.first_name,'NOT
AVAIL') or
upper(nvl(csi_hr.middle_name,'NOT AVAIL'))
nvl(csi_telecom.middle_name,'NOT AVAIL') or
upper(csi_hr.last_name) <> nvl(csi_telecom.last_name,'Not
Avail') )

;

sqlplus reads the above query and doesn't execute it. Then I type a /
and it does execute it.

This brings me much closer to my desired output, even if I do have to
mess around a bit in the sql script file.

The one thing that would be ideal is if I could 'merge' the outputs so
that instead of 2 reports, one after the other, I got
one report, with the 3 sets of names on one line.

I had expected that the union would do that.
That's indeed what the union would do. Check for empty lines in your
statement. There is one at the end, just before the ';'


Shakespeare


Reply With Quote
  #7  
Old   
Larry W. Virden
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 10:43 AM



On Mar 10, 11:58*am, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Quote:
Larry W. Virden schreef:





On Mar 9, 5:01 pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Larry W. Virden schreef:

I have the following set of tables and columns
T1:
Key1
Name
Dept.
T2:
Key2
Name
Dept
T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept
T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)
T4 maps the keys from one set of data to another. There should be rows
containing all the keys.
T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.
For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.
If the person's key is in t2, but no name is listed, I want to find
that as well.
I tried something to the effect of
select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
* * * * * *( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
* * * * * * *(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
* * * * * )
however, the resulting column values are not what I am expected.
I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.
Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.
Just did some quick reading of ypur post, but does this do what you ask?

Select 't2' source, t4.key0, ... some values here...
from t1,t2,t4
where t1.id=t4.key1 and t2.id=t4.key3
and t1.name <> nvl(t2.name,'xxx')
union 't3' source, t4.key0, etc..
from t1,t3,t4
where t1.id=t4.key1 and t3.id=t4.key3 and
t1.name <> nvl(t3.name,'xxx')

If not having an name in t2 or t3 means t2, t3.name is null you have to
take that into account as well, that's why the nvl(...'xxx') is there
(supposing no one is called 'xxx' of course)

Shakespeare- Hide quoted text -

- Show quoted text -

From an email

Thank you so much for your suggestion. I really appreciate you taking
the time to post a reply.

When I take your suggestion and plug in my information, oracle sqlplus
seems to not like the suggestion, but doesn't
produce a message saying why.

SQL*Plus: Release 10.2.0.2.0 - Production on Tue Mar 10 10:11:18 2009

Copyright (c) 1982, 2005, Oracle. *All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit
Production
With the Partitioning and Data Mining options

1 *select 'csi_security' source,
2 * * csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 * * csi_security.first_name, csi_security.initials, csi_security..last_name
4 *from csi_hr,csi_security,csi_core
5 *where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 * * * *csi_security.person_id=csi_core.sec_person_id and
7 * * * *csi_hr.first_name <> nvl(csi_security.first_name,'NotAvail')
8 * * * *or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 * * * *or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')
10 *union 'csi_telecom' source,
11 * * csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 * * csi_telecom.first_name, csi_telecom.middle_name,csi_telecom..last_name
13 *from csi_hr,csi_telecom,csi_core
14 *where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 * * * *csi_telecom.person_id=csi_core.sec_person_id and
16 * * * *csi_hr.first_name <> nvl(csi_telecom.first_name,'NotAvail') or
17 * * * *csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not Avail') or
18* * * * csi_hr.last_name <> nvl(csi_telecom.last_name,'Not Avail')

SQL

I can't see any obvious problem with my syntax, though I likely did
mess something up.

---
What error do you get?

I think you should put the part

csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 * * * *or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 * * * *or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')

within parentheses in both parts of your query

and there should be 'select' after the union *(which I did forget too)

Shakespeare

ps Please respond in the newsgroup, in stead of mailing directly, so others can participate!

Sorry - I will respond here as requested.

1. I don't actually get an error - sqlplus just sits there as if it
did what I asked.

So, I made the changes you suggested, and sqlplus continues to
indicate that it has read the select, but provides no indication that
it has executed it or if there is an error, what the error is:

* 1 *select 'csi_security' source,
* 2 * * csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
* 3 * * csi_security.first_name, csi_security.initials,
csi_security.last_name
* 4 *from csi_hr,csi_security,csi_core
* 5 *where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
* 6 * * * *csi_security.person_id=csi_core.sec_person_id and
* 7 * * * *(csi_hr.first_name <> nvl(csi_security.first_name,'Not
Avail')
* 8 * * * *or csi_hr.middle_name <> nvl(csi_security.initials,'Not
Avail')
* 9 * * * *or csi_hr.last_name <> nvl(csi_security.last_name,'Not
Avail') )
*10 *union select 'csi_telecom' source,
*11 * * csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
*12 * * csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
*13 *from csi_hr,csi_telecom,csi_core
*14 *where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
*15 * * * *csi_telecom.person_id=csi_core.sec_person_id and
*16 * * * *(csi_hr.first_name <> nvl(csi_telecom.first_name,'Not
Avail') or
*17 * * * *csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not
Avail') or
*18* * * * csi_hr.last_name <> nvl(csi_telecom.last_name,'Not
Avail') )
SQL

Maybe you can post the outcome of this query here?

* * select 'csi_security' source,
* * * * * *csi_hr.first_name,
* * * * * *csi_hr.middle_name,
* * * * * *csi_hr.last_name,
* * * * * *csi_security.first_name,
* * * * * *csi_security.initials,
* * * * * *csi_security.last_name
* * * from csi_hr,csi_security,csi_core
* * * where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
* * * * * * csi_security.person_id=csi_core.sec_person_id

Shakespeare- Hide quoted text -

- Show quoted text -
When I paste that select in, I get output from the 1558 rows selected,
with the security and hr data on the same line. There is no error or
probleml executing the select.


Reply With Quote
  #8  
Old   
Shakespeare
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 10:47 AM



Larry W. Virden schreef:
Quote:
On Mar 10, 11:58 am, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Larry W. Virden schreef:





On Mar 9, 5:01 pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Larry W. Virden schreef:
I have the following set of tables and columns
T1:
Key1
Name
Dept.
T2:
Key2
Name
Dept
T3:
Key2 (that is to say - the values here are the same "things" as table
2's key2)
Name
Dept
T4:
Key0
Key1 (values match T1.Key1)
Key2 (values match T2.Key2 and T3.Key2)
T4 maps the keys from one set of data to another. There should be rows
containing all the keys.
T1 is in my case the master list of names. I want to find out if there
are any rows in t1 where the person references also appears in t2 or
t3, but with a different name column value.
For examine, the person may be Thomas in t1, Tom in t2 and Tommy in
t3.
If the person's key is in t2, but no name is listed, I want to find
that as well.
I tried something to the effect of
select t1.name,t1.dept, t2.name,t2.dept, t3.name, t3.dept
from t1, t2, t3
where t1.key1 in (select key1 from t4) and
( (t2.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t2.name)) or
(t3.key2 in (select key2 from t4 where key1 = t1.key1 and
t1.name != t3.name))
)
however, the resulting column values are not what I am expected.
I have fiddled with the where clause a bit after reading several web
pages about solving this kind of problem, and the above is where I am
at now - still unsuccessful.
Does anyone have a suggestion for fixing the select so that it does
what I am trying for - I want to see the names (and departments) where
the rows should match, but are not matching.
Just did some quick reading of ypur post, but does this do what you ask?
Select 't2' source, t4.key0, ... some values here...
from t1,t2,t4
where t1.id=t4.key1 and t2.id=t4.key3
and t1.name <> nvl(t2.name,'xxx')
union 't3' source, t4.key0, etc..
from t1,t3,t4
where t1.id=t4.key1 and t3.id=t4.key3 and
t1.name <> nvl(t3.name,'xxx')
If not having an name in t2 or t3 means t2, t3.name is null you have to
take that into account as well, that's why the nvl(...'xxx') is there
(supposing no one is called 'xxx' of course)
Shakespeare- Hide quoted text -
- Show quoted text -
From an email
Thank you so much for your suggestion. I really appreciate you taking
the time to post a reply.
When I take your suggestion and plug in my information, oracle sqlplus
seems to not like the suggestion, but doesn't
produce a message saying why.
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Mar 10 10:11:18 2009
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit
Production
With the Partitioning and Data Mining options
1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials, csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')
10 union 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 csi_hr.first_name <> nvl(csi_telecom.first_name,'Not Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not Avail')
SQL
I can't see any obvious problem with my syntax, though I likely did
mess something up.
---
What error do you get?
I think you should put the part
csi_hr.first_name <> nvl(csi_security.first_name,'Not Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not Avail')
within parentheses in both parts of your query
and there should be 'select' after the union (which I did forget too)
Shakespeare
ps Please respond in the newsgroup, in stead of mailing directly, so others can participate!
Sorry - I will respond here as requested.
1. I don't actually get an error - sqlplus just sits there as if it
did what I asked.
So, I made the changes you suggested, and sqlplus continues to
indicate that it has read the select, but provides no indication that
it has executed it or if there is an error, what the error is:
1 select 'csi_security' source,
2 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
3 csi_security.first_name, csi_security.initials,
csi_security.last_name
4 from csi_hr,csi_security,csi_core
5 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
6 csi_security.person_id=csi_core.sec_person_id and
7 (csi_hr.first_name <> nvl(csi_security.first_name,'Not
Avail')
8 or csi_hr.middle_name <> nvl(csi_security.initials,'Not
Avail')
9 or csi_hr.last_name <> nvl(csi_security.last_name,'Not
Avail') )
10 union select 'csi_telecom' source,
11 csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
12 csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
13 from csi_hr,csi_telecom,csi_core
14 where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
15 csi_telecom.person_id=csi_core.sec_person_id and
16 (csi_hr.first_name <> nvl(csi_telecom.first_name,'Not
Avail') or
17 csi_hr.middle_name <> nvl(csi_telecom.middle_name,'Not
Avail') or
18* csi_hr.last_name <> nvl(csi_telecom.last_name,'Not
Avail') )
SQL
Maybe you can post the outcome of this query here?

select 'csi_security' source,
csi_hr.first_name,
csi_hr.middle_name,
csi_hr.last_name,
csi_security.first_name,
csi_security.initials,
csi_security.last_name
from csi_hr,csi_security,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_security.person_id=csi_core.sec_person_id

Shakespeare- Hide quoted text -

- Show quoted text -

When I paste that select in, I get output from the 1558 rows selected,
with the security and hr data on the same line. There is no error or
probleml executing the select.
I Think you are already there, it should work now if you use the union
and no empty lines. If you get no results back, it's the <>nvl part that
causes it.

Shakespeare


Reply With Quote
  #9  
Old   
Larry W. Virden
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 10:48 AM



On Mar 10, 12:19*pm, Shakespeare <what... (AT) xs4all (DOT) nl> wrote:
Quote:
Larry W. Virden schreef:
The one thing that would be ideal is if I could 'merge' the outputs so
that instead of 2 reports, one after the other, I got
one report, with the 3 sets of names on one line.

I had expected that the union would do that.

That's indeed what the union would do. Check for empty lines in your
statement. There is one at the end, just before the ';'

Shakespeare- Hide quoted text -

- Show quoted text -

Ah - removing the blank line before the ; now actually causes the
select to execute. However, what I get is two lines - the first column
of the first line says "csi_security" followed by the csi_hr name and
then the csi_security name. Then, 1348 lines later, there is a second
line which says "csi_telecom" in the first column, followed by the
csi_hr name and then the csi_telecom name.



The sql in question is

select 'csi_security' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_security.first_name, csi_security.initials,
csi_security.last_name
from csi_hr,csi_security,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_security.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_security.first_name,'NOT
AVAIL')
or upper(nvl(csi_hr.middle_name,'NOT AVAIL')) <> nvl
(csi_security.initials
,'NOT AVAIL')
or upper(csi_hr.last_name) <> nvl(csi_security.last_name,'NOT
AVAIL') )
union select 'csi_telecom' source,
csi_hr.first_name, csi_hr.middle_name, csi_hr.last_name,
csi_telecom.first_name, csi_telecom.middle_name,
csi_telecom.last_name
from csi_hr,csi_telecom,csi_core
where csi_hr.alt_emp_no=csi_core.hr_alt_emp_no and
csi_telecom.person_id=csi_core.sec_person_id and
(upper(csi_hr.first_name) <> nvl(csi_telecom.first_name,'NOT
AVAIL') or
upper(nvl(csi_hr.middle_name,'NOT AVAIL')) <>
nvl(csi_telecom.middle_name,'NOT AVAIL') or
upper(csi_hr.last_name) <> nvl(csi_telecom.last_name,'Not
Avail') )
;



Reply With Quote
  #10  
Old   
Larry W. Virden
 
Posts: n/a

Default Re: ISO: sql technique to select information from more than one table - 03-10-2009 , 10:54 AM



On Mar 10, 12:48*pm, "Larry W. Virden" <lvir... (AT) gmail (DOT) com> wrote:

Quote:
Ah - removing the blank line before the ; now actually causes the
select to execute. However, what I get is two lines - the first column
of the first line says "csi_security" followed by the csi_hr name and
then the csi_security name. Then, 1348 lines later, there is a second
line which says "csi_telecom" in the first column, followed by the
csi_hr name and then the csi_telecom name.

Let me clarify. I get 1700+ lines output. The first 1349 lines are the
results relating to csi_security. The last 356 lines are tagged as
being from the csi_telecom table.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.