What is the difference between IN and EXISTS operators in
SQL Server?
Answers were Sorted based on User's Feedback
Answer / monal
HERE'S THE SIMPLE ANSWER:
WHEN YOU USE 'IN', WHILE CHECKING FOR WHERE CONDITION SQL
SERVER ENGINE DOES WHOLE TABLE SCAN.
IF YOU USE 'EXISTS' AS SOON AS ENGINE FINDS THE REQUIRED
ROW IT WILL STOP EXECUTING QUERY AND GOING FURTHER SCANNING
TABLE.
SO BASICALLY EXISTS IS FASTER AS COMPARED TO IN.
Is This Answer Correct ? | 146 Yes | 14 No |
Answer / vijaykumar dolli
using the IN clause, you're telling the rule-based
optimizer that you want the inner query to drive the outer
query (think: IN = inside to outside).
When you write EXISTS in a where clause, you're telling the
optimizer that you want the outer query to be run first,
using each value to fetch a value from the inner query
(think: EXISTS = outside to inside).
Thank you
Is This Answer Correct ? | 106 Yes | 15 No |
Answer / pranab
IN:
Returns true if a specified value matches any value in a
sub-query or a list.
Exists:
Returns true if a sub-query contains any rows.
Is This Answer Correct ? | 27 Yes | 8 No |
Answer / navneet sharma
IN work like a OR in sql query but in is faster than OR in
case of IN server will search whole table
EXISTS is use to find the required row and does not search
whole table
Is This Answer Correct ? | 29 Yes | 16 No |
Answer / arslan
the basic difference between in and exists
let's take the example of for loop in c++ and in loops when you write break statement it will iterates until the condition of break statement will true this like exist and in
if you didn't put break in it then it will execute the whole loop
Is This Answer Correct ? | 7 Yes | 7 No |
Answer / raja
in operator returns the condition satisfied rows only
But in exists operator if any condition satisfied it will returns all the rows.
Is This Answer Correct ? | 6 Yes | 15 No |
Help!!!!!!!!!!!! My database has gone offline, it is highlighted as 'Suspect'. Foolishly, i haven't got a recent back up. Is there a way of quickly restoring the database? Thank you
What is the difference between createstatement and preparedstatement?
What are the five characteristics of good data?
Explain the usage of floor function in sql server.
How many types of keys are there?
What is dirty page?
What is an index?
Write a sql query to display the current date?
i have a table #temp1(id, Name groupname ) and record like this 1 R1 S 2 R3 S 3 R2 S 4 R4 D 5 R5 D 6 R6 K 7 R7 K 8 R8 L 9 R9 L 10 R10 L 11 R11 K and i want to display record based on user defind sorting order e.g. 1 R4 D 2 R5 D 3 R6 K 4 R7 K 5 R11 K 6 R1 S 7 R3 S 8 R2 S 9 R8 L 10 R9 L 11 R10 L
Observed that some SP’s / Jobs are processing late, how to troubleshoot to improve performance?
Describe how to use the linked server?
What are the different types of backups that exist?