The sql WHERE statement is used to select the data from the table with some conditions. This WHERE keyword comes follwed by the table name in SELECT statement. The General syntax of the sql WHERE statement is given below:
SELECT * FROM table_name WHERE column_name operator value
In WHERE statement used operators for checking the conditions. Some of the major operators list is given below.
| Operator | Operator description |
| = | Check the column_name and value is equal |
| <> | Check the column_name and value is not equal |
| > | Check the column_name is greater than value |
| < | Check the column_name is less than value |
| >= | Check the column_name is greater than or equal to value |
| <= | Check the column_name is less than or equal to value |
| LIKE | allows you to do search based on pattern |
| IN | allows you to do search based on value |
| BETWEEN | allows you to do search based on range |
Let us assume that we have the following table it shows the temperature information about the cities in india. Table name is temperature_information:
| City | AverageTemperature | Date |
| Chennai | 26 C | 11/21/2008 |
| Bombay | 27 C | 11/10/2008 |
| Calcutta | 30 C | 11/25/2008 |
| Bangalore | 18 C | 10/09/2008 |
| Delhi | 28 C | 12/29/2008 |
| Kochin | 17 C | 12/19/2008 |
Executed Query:
SELECT * FROM temperature_information WHERE City = 'Chennai'
Result:
| City | AverageTemperature | Date |
| Chennai | 26 C | 11/21/2008 |
Description:
it shows the chennai city temperature status with all columns.
Executed Query:
SELECT AverageTemperature FROM temperature_information WHERE City = 'Bangalore'
Result:
| AverageTemperature |
| 18 C |
Description:
it shows only the average temperature of the city bangalore.
Executed Query:
SELECT * FROM temperature_information WHERE AverageTemperature > 20
Result:
| City | AverageTemperature | Date |
| Chennai | 26 C | 11/21/2008 |
| Bombay | 27 C | 11/10/2008 |
| Calcutta | 30 C | 11/25/2008 |
| Delhi | 28 C | 12/29/2008 |
Description:
it shows the temperature details which average temperature is above than 20.
Executed Query:
SELECT * FROM temperature_information WHERE Date = '10/09/2008'
Result:
| City | AverageTemperature | Date |
| Bangalore | 18 C | 10/09/2008 |
Description:
it shows the temperature details which is Date equals 10/09/2008.