Explain how to use WHERE clause in SELECT statements?
The WHERE clause selects data from a table on conditional basis,
Ex :
Select EmployeeID from Employees where Position = 'Manager';
This Query displays the ID Numbers of all Managers from the table “Employees” and make sure that any text that appears in the statement is surrounded by single quotes (').
Select EmployeeID from Employees where Salary >= 50000;
This Query displays the ID Numbers of all Managers from the table “Employees” who gets salary of 50000 and above.
Select * from Employees where EmployeeName like ‘d%’
This Query will display the Employee names that start with ‘d’.
Select * from Employees where EmployeeName like ‘%m’
This Query will display the Employee names that end with ‘m’.
Select * from Employees where EmployeeName like ‘%la%’
This Query will display the Employee names that contain the word ‘la’.
Select * from Employees where EmployeeName in (‘Jerry’ , ‘Sam’)
This Query will display the Employee names starting with ‘Jerry’ and ‘Sam’.
Select * from Employees where EmployeeName between ‘Jerry’ and ‘Sam’
This Query will display the Employee names alphabetically between ‘Jerry’ and ‘Sam’.
Select * from Employees where EmployeeName not between ‘Jerry’ and ‘Sam’
This Query will display the Employee names outside the range of ‘Jerry’ and ‘Sam’.
Some commonly used logical operators in SQL are,
= “Equal”
<> or != “Not Equal”
< “Less than” > “Greater than”
<= “Less than or equal to” >= “Greater than or equal to”
BETWEEN “Used to search between an inclusive range”
LIKE “Used to Search for a pattern”
IN “Used to return based on the Exact value known”.
Ex :
Select EmployeeID from Employees where Position = 'Manager';
This Query displays the ID Numbers of all Managers from the table “Employees” and make sure that any text that appears in the statement is surrounded by single quotes (').
Select EmployeeID from Employees where Salary >= 50000;
This Query displays the ID Numbers of all Managers from the table “Employees” who gets salary of 50000 and above.
Select * from Employees where EmployeeName like ‘d%’
This Query will display the Employee names that start with ‘d’.
Select * from Employees where EmployeeName like ‘%m’
This Query will display the Employee names that end with ‘m’.
Select * from Employees where EmployeeName like ‘%la%’
This Query will display the Employee names that contain the word ‘la’.
Select * from Employees where EmployeeName in (‘Jerry’ , ‘Sam’)
This Query will display the Employee names starting with ‘Jerry’ and ‘Sam’.
Select * from Employees where EmployeeName between ‘Jerry’ and ‘Sam’
This Query will display the Employee names alphabetically between ‘Jerry’ and ‘Sam’.
Select * from Employees where EmployeeName not between ‘Jerry’ and ‘Sam’
This Query will display the Employee names outside the range of ‘Jerry’ and ‘Sam’.
Some commonly used logical operators in SQL are,
= “Equal”
<> or != “Not Equal”
< “Less than” > “Greater than”
<= “Less than or equal to” >= “Greater than or equal to”
BETWEEN “Used to search between an inclusive range”
LIKE “Used to Search for a pattern”
IN “Used to return based on the Exact value known”.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home