Kirill
Kirill

Reputation: 193

Replace two joins in one

I've two joins:

LEFT JOIN TransactionAmounts AS TAR ON T.orderID = TAR.orderID AND TAR.customerType = 1
LEFT JOIN TransactionAmounts AS TAA ON T.orderID = TAA.orderID AND TAA.customerType = 0

How I can replace this two joins for one? For improve performance

Upvotes: 2

Views: 55

Answers (1)

You can use

LEFT JOIN TransactionAmounts AS TAR ON T.orderID = TAR.orderID AND TAP.customerType in(0, 1 )

Or

LEFT JOIN TransactionAmounts AS TAR ON T.orderID = TAR.orderID AND (TAP.customerType = 0 OR TAP.customerType = 1)

Check your execution plan

Upvotes: 3

Related Questions