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 |
|
esermeh
Starting Member
3 Posts |
Posted - 2006-04-12 : 00:51:47
|
| I was trying to optimize this query on adventureworks. maybe it is possible. right now It is using a correlated sub query. -- to find employees hired at the same date. -- try to make it more efficient-- this one gives correct result-- this is a correlated quer because of that it gives a slow hash join. -- creating an index on hiredate impoves it 75%-------------------------------------- USE adventureworksSELECT E.EmployeeID, E.HireDate FROM HumanResources.Employee E WHERE E.HireDate IN ( SELECT EI.HireDate FROM HumanResources.Employee EI WHERE EI.employeeID !=E.employeeID ) ORDER BY E.EmployeeID |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2006-04-13 : 09:55:59
|
Try:USE adventureworksGOSELECT E.EmployeeID, E.HireDateFROM HumanResources.Employee AS EJOIN ( SELECT E.HireDate FROM HumanResources.Employee AS E GROUP BY E.HireDate HAVING COUNT(DISTINCT E.EmployeeID) > 1) AS tmpON tmp.HireDate = E.HireDateORDER BY E.EmployeeID Mark |
 |
|
|
esermeh
Starting Member
3 Posts |
Posted - 2006-04-14 : 03:50:05
|
| that is wonderfull :) it gives a merge join. i have read merge join is better than a hash join. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-04-14 : 07:09:29
|
it's better for some situations Go with the flow & have fun! Else fight the flow Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"] |
 |
|
|
|
|
|