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 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-06-25 : 04:24:17
|
| Hi All, Please let me know the difference between the following queries..----------------------------------------------------------Select Employee.* From Employee Inner Join Finmast OnFinmast.EmpID = Employee.EmpID Where FinMast.Status In(20,21,30)----------------------------------------------------------Select Employee.* From Employee Inner Join (Select EmpID From FinMast Where FinMast.Status in (20,21,20) Finmast On Finmast.EmpID = Employee.EmpID ----------------------------------------------------------Select Employee.* From Employee Inner Join FinMast On Finmast.EmpID = Employee.EmpID And FinMast.Status In (20,21,30)----------------------------------------------------------i checked through the execution plan all them returns the same time frame...and all the time required for execution of this query is same... so wHere does the differecnce lies. Thanks Complicated things can be done by simple thinking |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-06-25 : 10:43:38
|
| The 3 queries change the speicification of the inner join'ed result set only slightly. Query 1 joins the entire table and subsequently filters on the IN clause.Query 2 joins on a single column of the table FinMast, but only values that satisfy the IN clause.Query 3 joins the entire table, but only rows that satisfy the IN clause.Query 1 and 3 may return different results if a left outer join was used.Here's anotherSelect Employee.* From Employee WHERE EmpID IN (Select EmpID from FinMast WHERE Status IN (20,21,30))and anotherSELECT * FROM Employee EWHERE EXISTS (SELECT 1 FROM FinMast F WHERE F.EmpID = E.EmpID and F.Status IN (20,21,30)))and anotherSELECT * FROM Employee ELEFT OUTER JOIN FinMast F ON F.EmpID = E.EmpIDWHERE F.Status IN (20,21,30) and F.Status IS NOT NULLand anotherSELECT * FROM Employee EFULL OUTER JOIN FinMast F ON E.EmpID = F.EmpIDWHERE F.Status IN (20,21,30) AND E.EmpID IS NOT NULL AND F.EmpID IS NOT NULLand anotherSELECT * FROM Employee ECROSS JOIN FinMast FWHERE E.EmpID = F.EmpID AND F.Status IN (20,21,30) |
 |
|
|
andy8979
Starting Member
36 Posts |
Posted - 2005-06-27 : 04:14:20
|
Hi, Actually the execution plan shown is the fastest and the shortest execution path found by the complier, during the compilation it may vary for the same query depending on the number of records. May be if you have more records in your table it will show some different execution plan. if you want to use some specific indexes which are not being used in your query then you can specify the hint for the query to use the index. You can check out the bol for further specificaitons. Anuj. |
 |
|
|
|
|
|
|
|