If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > New Members & Introductions > sql query with left outer join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-11, 20:58
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sql query with left outer join

Hello, can anyone help me with this sql query please?
Iam trying to "retrieve the names of department managers who have no dependent " using ISNULL (instead of exists, not exists, in...)
Basically, i have the Employee table in which ssn is the primary key and the foreign key (dno) references the Department table. The dependent table is linked to Employee table by essn= ssn.

Any help is greatly appreciated.

Last edited by rikki27401; 08-03-11 at 21:02.
Reply With Quote
  #2 (permalink)  
Old 08-03-11, 22:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
we won't do homework assignments in this site

however, we will help, if you show what you've tried

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-04-11, 00:48
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sql query with left outer join

Thank you for your desire to help. I tried several statements but none seems to work.
Here what i got:
first i tried to retrieve the names department managers like this:
select name
from employee, department
where ssn=mgrssn;
That gives me the list of department mangers.
Next i tried to retrieve the employees with dependents so i can see which employee does not have a dependent
select essn
from dependent
where essn=ssn
not with those two lists , i can see the manager that does not have a dependent .But how to join the two lists to show the desired result is where iam stuck
I tried doing this and it is not working:
select name
from employee,department
where ssn=mgrssn
and(select essn
from dependent
where essn=ssn and mgrssn is null);
I also tried the left outer join but it would not work either.
Thanks for any guidance.
Reply With Quote
  #4 (permalink)  
Old 08-04-11, 02:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by rikki27401 View Post
select essn
from dependent
where essn=ssn
test this one again, i don't think it works
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-04-11, 07:01
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sql query with left outer join

Thank you but it did not work.
Reply With Quote
  #6 (permalink)  
Old 08-04-11, 08:05
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,263
so have you checked that yoiu have got data that will meet those criteria?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old 08-04-11, 08:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by rikki27401 View Post
Thank you but it did not work.
what was the error message?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 08-04-11, 09:03
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sql left outer join

yes i checked and there is one manager that does not have dependents .
I just cant seem to find a way to the name of that manger from the dependent table and employee table

For example, for these two attempts this is the error iam getting:
SQL> select name
2 from employee,department
3 where ssn=mgrssn
4 and (select essn
5 from dependent
6 where essn=ssn)
7 and mgrssn is null;
and mgrssn is null
*
ERROR at line 7:
ORA-00936: missing expression


SQL> select name
2 from employee,department
3 where ssn=mgrssn (select essn
4 from dependent
5 where essn is null);

*
ERROR at line 3:
ORA-00936: missing expression


Thank you.
Reply With Quote
  #9 (permalink)  
Old 08-04-11, 09:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
could you please go back to post #4 and do that one
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 08-04-11, 10:30
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sqlquery left outer join

I went back to post#4, still not working, not sure why.

Thanks
Reply With Quote
  #11 (permalink)  
Old 08-04-11, 10:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by rikki27401 View Post
still not working,
sorry, i am not familiar with that particular error message

can you give some more detail about what happened when you tested it?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 08-04-11, 10:55
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
sql left outer join

Thank you.
basically iam trying to acchive the same result as below only without using"not in, not exists in but rather with IS NULL and maybe an outer join)
select name
from employee,department
where ssn=mgrssn
and mgrssn not in(select essn
from dependent);

This one gives me the result i want. but now i need to get the say result ,this time using "IS NULL " or an other join.

Thanks for your efforts
Reply With Quote
  #13 (permalink)  
Old 08-04-11, 10:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
do you understand how to qualify a column name with its table name?

because you are showing us queries that are impossible for us to understand, since you aren't qualifying your columns properly
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 08-04-11, 16:08
rikki27401 rikki27401 is offline
Registered User
 
Join Date: Aug 2011
Posts: 7
Ok, sorry.
select employee.name
2 from employee,department
3 where employee.ssn=department.mgrssn (select dependent.essn
4 from dependent
5 where depedent.essn is null);
Reply With Quote
  #15 (permalink)  
Old 08-04-11, 16:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
that's nice, but you keep sidestepping my question

please qualify the columns in the query in post #4
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On