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 |
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-04 : 01:23:44
|
| hi all,hi pls see my samples tables and required output below..dept tabledeptid deptname 100 maths 101 physics102 pscycologyemp tableempid empname deptid1000 john 1001001 samuel 1011002 albert 1001003 joseph 1001004 ann 101required output:102 pscycology I need the query using joining tables and not using IN/NOT IN keywords.ok tanx in advance |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2008-12-04 : 01:56:57
|
is this homework? after 142 posts here?use a left join:select d.deptid, deptnamefrom dept d left join emp e on d.deptid = e.deptid where e.deptid is null |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-04 : 02:05:11
|
Alsoselect d.deptid, deptnamefrom dept d WHERE NOT EXISTS(SELECT 1 FROM emp where deptid = d.deptid) |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-04 : 02:05:34
|
| hi nathan, yes its a homework.. |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-04 : 02:08:11
|
| hi visakh, second table emp may have records of 1 lakh or above.. so wats ur opinion about performance of query? shall i use ur query or nathan's query ?ok tanx.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-04 : 02:16:07
|
quote: Originally posted by soorajtnpki hi visakh, second table emp may have records of 1 lakh or above.. so wats ur opinion about performance of query? shall i use ur query or nathan's query ?ok tanx..
test it and see how much time each takes. |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2008-12-04 : 02:20:06
|
| and examine exec plan of each to learn why one takes longer than the other.learning is fun.Nathan Skerl |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-04 : 02:38:32
|
| yup but not everybody knows that fact........ |
 |
|
|
|
|
|