Your Ad Here
SQL Basic

Bookmark and Share
SQL WHERE

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:

CityAverageTemperatureDate
Chennai26 C11/21/2008
Bombay27 C11/10/2008
Calcutta30 C11/25/2008
Bangalore18 C10/09/2008
Delhi28 C12/29/2008
Kochin17 C12/19/2008
 
Example 1:

Executed Query:
SELECT * FROM temperature_information WHERE City = 'Chennai'

Result:
CityAverageTemperatureDate
Chennai 26 C 11/21/2008

Description:
it shows the chennai city temperature status with all columns.
 
Example 2:

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.
 
Example 3:

Executed Query:
SELECT * FROM temperature_information WHERE AverageTemperature > 20

Result:
CityAverageTemperatureDate
Chennai26 C11/21/2008
Bombay27 C11/10/2008
Calcutta30 C11/25/2008
Delhi28 C12/29/2008

Description:
it shows the temperature details which average temperature is above than 20.
 
Example 4:

Executed Query:
SELECT * FROM temperature_information WHERE Date = '10/09/2008'

Result:
CityAverageTemperatureDate
Bangalore18 C10/09/2008

Description:
it shows the temperature details which is Date equals 10/09/2008.

Today's Deal