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 |
|
azimuth73
Starting Member
3 Posts |
Posted - 2007-06-14 : 11:32:14
|
hi im a little bit confused. are the two pieces of code similar? what are the differences. i really need to know that coz i wont get access to a SQL machine until monday.select lastnamefrom empwhere sex = 'F' and salary>( select avg(salary) from emp group by sex having sex='M' ) select lastnamefrom empwhere sex = 'F' and salary>( select avg(salary) from emp where sex='M' ) also is it wise to use Group by and having in sub-queries? |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-14 : 11:38:57
|
| Although both queries produces same result, GROUP BY and HAVING is unnecessary where you can simply put same condition in WHERE clause.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-14 : 11:41:01
|
| I think I read that SQL Query Plan Optimizer will automatically move HAVING to WHERE clause where appropriate.Kristen |
 |
|
|
|
|
|