Using SQL WHERE clause

No comments
SQL where clause is used to get the rows from table based on some specified conditions, these conditions can be defined using WHERE clause.
+----+--------+---------+------+
| ID | FNAME  | LNAME   | AGE  |
+----+--------+---------+------+
|  1 | AKSHAY | KUMAR   |   12 |
|  2 | JONTY  | RHODES  |   40 |
|  3 | JOHNY  | DEPP    |   45 |
|  4 | JESSIE | PINKMAN |   25 |
+----+--------+---------+------+

SQL WHERE clause syntax and example in MySQl

Suppose we want to get all the rows from CUSTOMER table where country is INDIA.
SELECT * FROM CUSTOMER WHERE COUNTRY = 'INDIA';
+----+--------+-------+------+---------+
| ID | FNAME  | LNAME | AGE  | COUNTRY |
+----+--------+-------+------+---------+
|  1 | AKSHAY | KUMAR |   12 | INDIA   |
|  3 | JOHNY  | DEPP  |   45 | INDIA   |
+----+--------+-------+------+---------+
Here we can see that we have got only those rows for which condition was specified in WHERE clause. Here to specify the condition we have used = operator, but there are other operators which we can use with where clause.

Operators used with WHERE clause - SQL

Operator Details
= Equal
<> Not equal. Or some other versions of SQL we us !=
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column

No comments :

Post a Comment