Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
boybles
Starting Member
23 Posts |
Posted - 2011-11-03 : 23:50:23
|
I'm trying to join the following tables such that the resulting query will display all of the EmployeeIDs and the HobbyIDs that they DON'T have. Please refer to the following and advise. I'm completely stumped. Thanks!!! Tony TABLES============Employee-------------------EmployeeID (Number 3)EmployeeName (Varchar2 25)Hobby-------------------HobbyID (Number 3)HobbyName (Varchar2 25)EmployeeHobbyMap-------------------EmployeeHobbyMapID (Number 3)EmployeeID (Number 3)HobbyID (Number 3)DATA==========Employee-----------------------1| John Smith2| Jane Washington3| Tom White4| Ken JamesHobby-------------------------1| Fishing2| Tennis3| Soccer4| GardeningEmployeeHobbyMap-------------------1|1|22|1|3 3|1|44|2|15|2|36|3|17|3|28|3|39|3|410|4|2DESIRED RESULTS===============EmployeeID|HobbyID------------------1|12|22|44|14|34|4 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-11-04 : 00:33:39
|
[code]select e.EmployeeID, h.HobbyIDfrom Employee e cross join Hobby hwhere not exists ( select * from EmployeeHobbyMap eh where eh.EmployeeID = e.EmployeeID and eh.HobbyID = h.HobbyID )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
boybles
Starting Member
23 Posts |
Posted - 2011-11-04 : 02:25:56
|
| Thank you, Khtan. That is exactly what I was looking for...and it really put me on the right track. I have a couple other things I need to work out...but this puts me on the right track. Thanks again for your invaluable help.Tony [:-)] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-11-04 : 02:30:11
|
you are welcome KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|