Reputation: 851
I'm doing some SQL optimizations but my SQL fu could use some improvement...
Why do a join on a subquery, could this just be a straight inner join, or am I missing something?
-- Why do a join and a subquery?
-- INNER JOIN (
-- SELECT client_id, session_id, id, customer_id, validity, machine_id,
-- utc_date_completed, itemStatus, totalValue, utc_date_updated,
-- itemValue, itemId, itemName, customField1, customField2, itemPage, itemCurrency
-- FROM data.dashboard WITH(NOLOCK)
-- WHERE client_id = @client_id
-- ) d ON cm.client_id = d.client_id
INNER JOIN data.dashboard AS d ON cm.client_id = d.client_id AND d.client_id = @client_id
Upvotes: 0
Views: 54
Reputation: 16361
Yes, functionnally they are the same, and you should have better performance doing an INNER JOIN
. Check on the execution plan for performance.
And it is far more readable and maintainable.
Upvotes: 1