What is different between Like And IN?

Posted by vimalrnsin-17147 under Sql Server on 7/31/2012 | Points: 10 | Views : 977 | Status : [Member] | Replies : 5
I have knowledge in Like and IN,But I want to Deeply knowledge in Like and IN




Responses

Posted by: CGN007 on: 8/1/2012 [Member] Silver | Points: 25

Up
0
Down
The LIKE operator
. s LIKE p: pattern matching on strings
. p may contain two special symbols:
% = any sequence of characters
_ = any single character
Eg:
 SELECT * FROM employee WHERE name LIKE 'A%';

Display records where the name starts with 'A'
IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
SELECT * FROM employee WHERE Name IN ('Raju','Ramu')


vimalrnsin-17147, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kirthiga on: 8/1/2012 [Member] Starter | Points: 25

Up
0
Down
LIKE Operator

Like Operator used to search the expression based on specific pattern.

If we want the specific data but we dont know exactly what it may be then LIKE Operator is used.


select * from TableName where ColumnName Like '%part_of_value%'


IN Operator

IN Operator used to search group of expression

If we want more than one value in where condition IN Operator is used

select * from TableName where ColumnName IN ('value1','value2')


vimalrnsin-17147, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/1/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
LIKE : - Column value's similar to specified character.
IN : - Column value's equal to any one of a specified set of values.

For more details...
http://beginner-sql-tutorial.com/sql-like-in-operators.htm

vimalrnsin-17147, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/4/2012 [Member] Bronze | Points: 25

Up
0
Down
LIKE

Like is used for pattern search.
If you want to know the list of all persons whose firstname starts with peter then use like operator

select * from persons where firstname like 'peter%'

IN

IN operator is much shorter and easier to read when you are testing for more than two or three values.
The IN operator allows you to specify multiple values in a WHERE clause.
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')



vimalrnsin-17147, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Maheshvishnu on: 9/4/2012 [Member] Starter | Points: 25

Up
0
Down
IN:

We can compare more than one column value at a time.

eg: i want data from table where employee name may be mahesh,suresh


select * from employee where ename in('mahesh','suresh')

LIKE:

generally used to work with characters in column.

eg: i want the data from table where employee name starts with m

select * from employee where ename LIKE 'm%'



mahesh

vimalrnsin-17147, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response