What is better in the offer WHERE?
I have a large table with FK on a small table. I can search directly on FK, or I can join the FK table and set a restriction WHEREon the joined table. Which is better / preferable?
So this is:
SELECT lt.* FROM LargeTable lt
WHERE lt.SomeId in(12,55)
Or that:
SELECT lt.* FROM LargeTable lt
INNER JOIN SmallTable st ON lt.SomeId=st.ItemId
WHERE st.Id in(12,55)
I tested this with help Set statistics time on, but I did not expect this as a result. Who can explain what is going on here?
First test without attachment:
(946 row(s) affected)
SQL Server Execution Times:
CPU time = 1544 ms, elapsed time = 1580 ms.
Second test with connection
(946 row(s) affected)
SQL Server Execution Times:
CPU time = 2636 ms, elapsed time = 366 ms.
EDIT: SELECT Id SELECT *, , 25%, 75% .