The WHERE clause is used to extract only those records that fulfill a specified criterion.
SQL WHERE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
FROM table_name
WHERE column_name operator value
Table Name : CustMast
| 
custcode | 
custname | 
city | 
qty | 
rate | 
| 
1 | 
Siva | 
Srivilliputtur | 
50 | 
70 | 
| 
2 | 
Bala | 
Sivakasi | 
30 | 
56 | 
| 
3 | 
Kanna | 
100 | 
200 | |
| 
4 | 
Vijay | 
Chennai | 
30 | 
30 | 
| 
5 | 
Kodee | 
Srivilliputtur | 
60 | 
30 | 
| 
5 | 
Kodee | 
Srivilliputtur | 
60 | 
30 | 
For TEXT values:
Ex: 1
Select CustName,City from CustMast where Custname='Siva'
OutPut :
| 
custname | 
city | 
| 
Siva | 
Srivilliputtur | 
Ex: 2
Wrong Below Coding
Select CustName,City from CustMast where Custname=Siva
Error : Invalid column name 'siva'.
Note: ( SQL uses single quotes around text values (most database systems will also accept double quotes).
Although, numeric values should not be enclosed in quotes.)
                                                   For NUMERIC  values:
This is correct:
SELECT * FROM Persons WHERE Year=1965
This is wrong:
SELECT * FROM Persons WHERE Year='1965'
This is correct:
SELECT * FROM Persons WHERE Year=1965
This is wrong:
SELECT * FROM Persons WHERE Year='1965'
Operators Allowed in the WHERE Clause
With the WHERE clause, the following operators can be used:| 
Operator | 
Description | 
| 
= | 
Equal | 
| 
<> | 
Not equal | 
| 
> | 
Greater then | 
| 
< | 
Less than | 
| 
>= | 
Greater than or equal | 
| 
<= | 
Less than or equal | 
| 
BETWEEN | 
Between an inclusive range | 
| 
LIKE | 
Search for a pattern | 
| 
IN | 
If you know the exact value you want to return for at
  least one of the columns | 
Note: In some versions of SQL the <> operator may be written as !=



 
0 comments:
Post a Comment