Thursday, May 3, 2012

SQL IN

Welcome Friends to this post where I will be discussing about the SQL IN Operator, basically this is very simple, and helps to extract records according to values of a Column.

Lets have a look at out Employee Table.

PID    Name        Designation
222    Whiskey        Moderator
444    Onty              Admin
111     Gaurav          Admin
333    Kumaar         Admin
555    Rishabh         Admin
666    Rose             Admin
888    White            Admin
999    Mikey           Admin

Now once again our Manager comes and asks for info about Whiskey, Rose and Mikey.

So in these case, what we can do is, use the SQL IN Query.

Syntax:

SELECT * FROM table_name
WHERE column_name IN (value1, value2, value3, . . .)


So for our purpose we would use the below query

SELECT * FROM Employee
WHERE Name IN ("Whiskey", "Rose", "Mikey")


So with this query, our result set will be:

PID    Name        Designation
222     Whiskey       Moderator
666     Rose             Admin
999     Mikey           Admin

This is cool isn't it? Anyways this is all what I have for you in this post.

Hope you enjoyed it and Don't forget to check my next post.

Thank You!

0 comments:

Post a Comment