SQL Difference Between Using = and IN

What is the difference between using the following statements in a WHERE clause in SQL?

WHERE STUDENTID=7

or

WHERE STUDENTID IN (7)

Is there a recommended / optimal choice?

+4
source share
5 answers

Use IN if you are doing multiple or, for example,

Where StudentID = 7 or StudentID = 6 or StudentID = 5

Will be

Where StudentID IN (5,6,7)

Otherwise, just use =

+6
source

There is no functional difference, the result is the same.

The performance will be different if the database processes them differently, but it is likely that the database will recognize that you are using exactly one value in the expression inand actually make up an execution plan as if it were the first.

, , , , in.

+5

IN - :

( StudentID = 7 or StudentID = 6 or ... )

NULL .

+2

, .., , , SQL, Oracle OPTIMIZER , -write, . - , , . , .

IN -

StudentID = 7 StudentID = 6 StudentID = 5

OR, IN.

+2

, . , IN.

:

a, b c .

=, :

Select * from table_name where name = 'a' or name = 'b' or name = 'c' 

IN

Select * from table_name where name in('a','b','c')
+1

All Articles