SQL Where Condition sql-where-condition.pdf

Overview

Where condition is used to fetch data from the table on the basis of some conditions on some of the data columns.

Syntax

Syntax for using where clause is

SELECT * FROM table_name WHERE (conditions);

Example

Let us have a deeper look on this with the help of an example

Let us consider our hostel_list table which contains the list of hostels.

+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
|  1 | ASHOK BHAVAN | 2 | 1090 |
|  2 | KAILASH BHAVAN | 2 | 990 |
|  3 | RUDRAKSH BHAVAN | 2 | 990 |
|  4 | KAVERI BHAVAN | 1 | 690 |
|  5 | BHAGIRATHI BHAVAN | 4 | 2140 |
|  6 | NARMADA BHAVAN | 6 | 3240 |
|  7 | GANGA BHAVAN | 1 | 780 |
|  8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+

So Lets fetch the list of hostel from our hostel_list table which has occupancy = 2;

SELECT * FROM hostel_list WHERE occupancy = 2;
+----+-----------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-----------------+-----------+----------+
|  1 | ASHOK BHAVAN | 2 | 1090 |
|  2 | KAILASH BHAVAN | 2 | 990 |
|  3 | RUDRAKSH BHAVAN | 2 | 990 |
+----+-----------------+-----------+----------+



This article is contributed by Ankur Rastogi on Fri Mar 18 2016 22:16:29 GMT+0530 (IST)

If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.