What is the difference between WHERE AND IN?
OR
1. SELECT * FROM EMPLOYEE WHERE EMPID=123
2. SELECT * FROM EMPLOYEE WHERE EMPID IN (123)
WHAT IS THE DIFFERENCE?

Answers were Sorted based on User's Feedback



What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / jaipal singh

The IN operator allows you to specify multiple values in a
WHERE clause.
if we want to select the persons with a EMPID equal to 1,2
and 3 from the table above.
and simply where clause allow you to select ony whose EmpID
is 123.it is main difference

Is This Answer Correct ?    21 Yes 3 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / aditya bisoi

Actually Both Query will return Same Result....
But Performance wise 1st Query better..Bcz it will return the Exact Record with out check hole record in the table....

But when we use IN operator then the sql engine will do the Table scan and retrive the Result...

Is This Answer Correct ?    5 Yes 0 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / abinash

Jaipal Sing: Lets say I will keep only one value (123) in IN
clause. In this case what is the real difference??
This is how Question asked to me!! and I am answer less...

Is This Answer Correct ?    6 Yes 2 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / chandan

IN operator is used to specify multiple variable.
while in this query both result will be same.

Is This Answer Correct ?    5 Yes 1 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / saiteja

In the case of where clause it displays single row,or operator can be placed in where clause in oreder to extend rows.
In IN operator at a time we can place empid multiple times but they must be unique.
ex:
(
select * from emp
where empid=123
);
By using OR operator:
(
select * from emp
where empid=123 or empid=234
);
By using IN operator:
(
select * from emp
where empid IN(123)
);
accordidg to the question the output will be same in both thae cases..

Is This Answer Correct ?    3 Yes 0 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / g.m. ershad

1)select * from test2 where id=44
Output -
ID NAME
44 Ershad

2) sELECT * FROM test2 WHERE ID IN (44)
Output -

ID NAME
44 Ershad

both will return same output

Is This Answer Correct ?    6 Yes 4 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / soumya ghosh

Both of them will return the same record
But as per the first sentence of the question, WHERE is a Clause whereas IN is a Operator. That is the difference between both.

Is This Answer Correct ?    2 Yes 0 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / dinesh sharma

In WHERE Clause when the condition match no further scan of
table stop scanning the table after condition match.

where as IN operator It scan the full table either condition
match or not.

Is This Answer Correct ?    2 Yes 0 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / shashi kishor prasad

The where Clause allows you to give so many conditions like
in the above case you can use
select * from employee where empid >122
select * from employee where empid <125
select * from employee where empid between 122 and 125
select * from employee where empid is not null(if null allowed)
and many moer..........
where as
The in clause allows you to give a no of values inside the
parenthesis decided by you like

select * from employee where empid in(123,1234,125)
or
select * from employee where empid in(select empid from
employee where empid>200)

Is This Answer Correct ?    1 Yes 0 No

What is the difference between WHERE AND IN? OR 1. SELECT * FROM EMPLOYEE WHERE EMPID=123 2. SELE..

Answer / mohan

both are same

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Can Having clause be used without Group by clause?

6 Answers   CarrizalSoft Technologies, CSC, CTS,


How many types of triggers in sql server?

0 Answers  


What is model database in sql server?

0 Answers  


How to find the list of fixed hard drive and free space on server?

0 Answers  


What is the architecture of ms sql reporting service?

0 Answers  






What is surrogate key? : sql server analysis services, ssas

0 Answers  


How to determine the service pack currently installed on SQL Server?

4 Answers   HCL,


How to transfer Logins from SQL Server 2000 to 2005

2 Answers  


What are some of the pros and cons of not dropping the sql server builtinadministrators group? : sql server security

0 Answers  


difference between truncate, delete aur drop?

2 Answers  


How do I find the port number for sql server?

0 Answers  


What is difference between stored procedure & function?

3 Answers   CarrizalSoft Technologies, Concept Infoway, TATA,


Categories