HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

SQL SERVER Which Query is faster

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
serversqlqueryfasterwhich

Problem

Which query is faster:

Query A

SELECT I.ItemName
FROM Location L
INNER JOIN Items I ON I.LocationID = L.LocationID
WHERE L.LocationID = 1


Execution Plan

Query B

SELECT ItemName
FROM Items 
WHERE ItemID IN (
SELECT ItemID
FROM  Items
WHERE LocationID = 1)


Execution Plan

Solution

Neither. Try:

SELECT I.ItemName
FROM Items I
WHERE I.LocationID = 1


...and add a covering index on LocationID with INCLUDE column ItemName .

Code Snippets

SELECT I.ItemName
FROM Items I
WHERE I.LocationID = 1

Context

StackExchange Database Administrators Q#279502, answer score: 12

Revisions (0)

No revisions yet.