Query optimization - using conditions on JOIN instead of with WHERE clause
问题 Inside an SP I need to find out the Id's of some clients of the first account whose Code matches any of the second account's clients. I wrote the following query that works - SELECT DISTINCT cil.Id FROM ClientIdList AS cil INNER JOIN Client AS c1 ON cil.Id = c1.Id INNER JOIN Client AS c2 ON c1.Code = c2.Code WHERE c2.AccountId = 2 ORDER BY cil.Id Here ClientIdList is a single-column table-type variable which holds the Ids of the selected clients from the first account (and I need to use this