java2db

Use of WHERE clause in sql



The  main use of  WHERE clause in SQL is to specify a condition , to filter  the rows  for the result.We can distinguish  simple and compound  conditions. simple conditions typically contain one of the SQL comparison operators listed below.
WHERE clause SQL comparison operators :

Operator Description
< Less than
<= Less than or equals to
> Greater than
>= Greater than or equals to
= Equals to
<> Not equal to (alternative syntax: !=)
IN To specify multiple possible values for a column (Ex : IN (‘Pen’,’Book’,’Bag’) )
LIKE Search for a pattern (Ex : %D% )
BETWEEN Values between a range

 

Syntax:

SELECT <COLUMN NAMES> FROM  <TABLE NAME> WHERE <CONDITION>;

Example table :

E_NO
E_NAME
E_GENDER
E_SALARY
E_ADDRESS
E_JOIN_DATE
E_IN_TIME
1 Rose S F 10000 street10,xxx,UK 03-MAR-13 10-MAR-13 12.10.10.0
2 Tom M 15000 street11,xxx,UK 04-MAY-13 12-MAY-13 12.10.10.0
3 James M 9000 street12,xxx,UK 12-jan-14 12-jan-14 12.10.10.0
4 Mark M 8000 street13,xxx,UK 16-Feb-14 16-Feb-14 12.10.10.0

WHERE clauseWHERE clause with a Simple Condition :

When we execute the above SQL statement on the example table , the out put will be like this.

E_NO
E_NAME
E_GENDER
E_SALARY
E_ADDRESS
E_JOIN_DATE
E_IN_TIME
1 Rose S F 10000 street10,xxx,UK 03-MAR-13 10-MAR-13 12.10.10.0
2 Tom M 15000 street11,xxx,UK 04-MAY-13 12-MAY-13 12.10.10.0

 

Another example of a WHERE clause with a simple condition, this time using the “<>” ( or !=)   operator.

The result of the above SQL statement as follows .

E_NO
E_NAME
E_GENDER
E_SALARY
E_ADDRESS
E_JOIN_DATE
E_IN_TIME
2 Tom M 15000 street11,xxx,UK 04-MAY-13 12-MAY-13 12.10.10.0
3 James M 9000 street12,xxx,UK 12-jan-14 12-jan-14 12.10.10.0
4 Mark M 8000 street13,xxx,UK 16-Feb-14 16-Feb-14 12.10.10.0



Related Posts :
Sql FOREIGN KEY constraint on table column
Sql CHECK constraint on table column
Sql NOT NULL constraint on table column
Sql UNIQUE constraint on table column
Sql PRIMARY KEY constraint on table column
Sql full outer join on tables with an example
Sql right outer join on tables with an example
Sql left outer join on tables with an example
   [will not be published]



^ <