| |
|
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.
|
 |

08-03-11, 20:58
|
|
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.
|

08-03-11, 22:31
|
|
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

|
|

08-04-11, 00:48
|
|
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.
|
|

08-04-11, 02:51
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
|
|
Quote:
Originally Posted by rikki27401
select essn
from dependent
where essn=ssn
|
test this one again, i don't think it works
|
|

08-04-11, 07:01
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 7
|
|
|
sql query with left outer join
Thank you but it did not work.
|
|

08-04-11, 08:05
|
|
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
|
|

08-04-11, 08:31
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
|
|
Quote:
Originally Posted by rikki27401
Thank you but it did not work.
|
what was the error message?
|
|

08-04-11, 09:03
|
|
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.
|
|

08-04-11, 09:21
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
|
|
could you please go back to post #4 and do that one
|
|

08-04-11, 10:30
|
|
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
|
|

08-04-11, 10:32
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
|
|
Quote:
Originally Posted by rikki27401
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?
|
|

08-04-11, 10:55
|
|
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
|
|

08-04-11, 10:57
|
|
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
|
|

08-04-11, 16:08
|
|
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);
|
|

08-04-11, 16:48
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|