optimization - SQL Server IN vs = in query(for one value) -
First of all, sorry for the obscure topic name (I could not think anything better).
One such answer came to me to think that when I chuck = for IN, then there really is any effect or not.
Select 1 ID, select # union in 'abc', select 2, 'ABCD' union 3, select 'ABCDE' # where id = 1---- - Select Question 1 * # from where in ID (1) ------ Question 2 I examined query plans for both questions and found them Perhaps this is probably the reason that the example was simple).
But am I violating the best practice while using IN ? Ensure that some should have overheads associated with it, because one IN can handle more than one item and even SELECTS . I know that in the case of IN features a lot more, but when id = 1 , select
* # From where id = (SELECT id to # a where id = 1) ------ Choose 3 * from * to # where in id (SELECT id # from where id = 1) ----- - query4 < / Code> query3 will fail, while query4 will work, in this way I would like to change = with IN in the future in my code About any potential trade-offs I want to know.
Edit I'm interested in learning how (in a different way?) SQL engine deals with them statement
If I can do Ignore the display aspect of your question, then there is a design problem. You need a code for your intent so that when someone reads your code, then there is a better chance of understanding what you were trying to achieve. Do you expect from # SELECT id where id = 1 to exactly return a record? If so, then use '=' if you expect it to return zero or more then '=' would be wrong
Comments
Post a Comment