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 |
|
cfgcjm
Starting Member
3 Posts |
Posted - 2009-04-22 : 22:50:41
|
can someone explain to me how one would rewrite this query as a nested subquery?SELECT OWNER.LastName, OWNER.PhoneFROM OWNER, PURCHASEWHERE OWNER.SSN# = PURCHASE.SSN#AND OWNER.City = ’Philadelphia’ORDER BY OWNER.LastName ASC; |
|
|
Kumar_Anil
Yak Posting Veteran
68 Posts |
Posted - 2009-04-23 : 00:06:14
|
| may be something like this....regards,Anil Kumar--------------------------------select Lastname, Phone from Owner where city = 'Philadelphia' and ssn in (select ssn from purchase)order by 1;The above query might be expensive if you are talking about large tables, so you might want to substitute "in" with "exists" if you are thinking on performance lines. |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-04-23 : 00:47:10
|
| You can also ue inner join for this....iF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
 |
|
|
aprichard
Yak Posting Veteran
62 Posts |
Posted - 2009-04-23 : 03:18:03
|
| Hi, Kumar,"EXISTS" will increase performace when campare to "IN" in all cases.Is it so? |
 |
|
|
|
|
|