Wednesday, April 25, 2012

SQL WHERE Operators


Hello Friends so now that we know what WHERE Clause does, which basically extracts records from columns, when certain conditions matches. And while applying conditions we use certain operators to match the conditions or to compare.

So In this post, I will speak about the various Operators that can be used with WHERE Clause:

Operator                Description

=                             Equals

<> / !=                     Not Equals

>                             Greater Than

<                             Less Than

>=                           Greater Than or Equals

<=                           Less Than or Equals

LIKE                       Looks For Some Matching Patterns

IN                            For Specifying Multiple possible values in a column

BETWEEN              Between some Range(This varies from Database)

Lets say we have a Table Named Employee, where we have a column named "Age", which holds info about ages of all Employees in a certain company.

So, for our Query:

SELECT * FROM Employee WHERE Age>18

Will display all the records whose age is greater than 18, same goes from the less than operator.

SELECT * FROM Employee WHERE Age>=18

Will display all the records whose age is greater than and equal to 18, for the previous query, we wont get records of employee whose age is 18, it will show the results above 18, but this will start from 18, same goes for less than equal operator

Lets Say, in the same Employee Table, we have another column named EmpName,

So our Query:

SELECT * FROM Employee WHERE EmpName LIKE 'a%'

So with this query it will show all the records of Employees, who names starts with a, so if our EmpName Column has 5 records and the names are Alfred, Diana, Aini, Ricky, Andrew.

It will display the the records of Alfred, Aini and Andrew.

IN and BETWEEN is not used much, because they are not consistent, gradually, I will show you the usage of IN and BETWEEN in relevant posts.

Thats all for now, hope you enjoyed the post. Don't forget to watch my next post.

Thank You!

0 comments:

Post a Comment