| < PREVIOUS | NEXT > |
WHERE CLAUSE
For filtering record we use Where Clause, extracting information that fulfill a specified condition.
WHERE SYNTAX
SELECT column1, column2, ...
FROM table_name
WHERE condition;
WHERE is used with SELECT, UPDATE, DELETE, etc.
EXAMPLE
Suppose there is a Table name as “CustomerComplaint” having CustomerID, CustomerName, ProductName Issue, City, PostalCode and Country as columns.
If we want to select all customers from India.
SELECT * FROM Customers
WHERE Country='India';
If we want to select customer which is having customerID is 12
SELECT * FROM Customers
WHERE CustomerID=12;
Operations in SQL using WHERE Clause
- EQUAL =
SELECT * FROM CustomerComplaint WHERE PostalCode = 226001;Above statement will return all records having postal code as 2206001
- For Greater than > || Less than < || Greater than or equal >= || Less than Less than or equal <= || Not equal <>
SELECT * FROM CustomerComplaint WHERE CustomerId > 3;It will return all record having Customer ID greater than 3
- BETWEEN
SELECT * FROM CustomerComplaint WHERE CustomerID BETWEEN 2 AND 5;It will return all record having Customer ID between 2 to 5
- LIKE
SELECT * FROM CustomerComplaint WHERE ProductName LIKE ‘%P’;It will return all the record ending with letter P
- IN
SELECT * FROM CustomerComplaint WHERE City IN (“Lucknow”, “Berlin”);It will return all possible values where city is Lucknow and Berlin
Arguement value of IN are Case Sensitive
| < PREVIOUS | NEXT > |