WHERE Clause Where clause is used to limit the retrieval of the data from the database for given condition and use the key word WHERE.Where clause follows the FROM clause in the SQL Statement. Syntax- SELECT *|[DISTINCT]Column|expression [Alias] From Table_Name; [WHERE <Condition(s)>] SELECT -a list of columns * -Select the all columns DISTINCT-suppresses the duplicates alias-alternate name of the column(s) that is/are used as the heading of that column(s). Table_name-specifies the table name containing the column(s). WHERE<Condition(s)>- the condition must meet to retrieve the data from the database. Note- Condition is combination of column names,constants,variables,expressions and comparison operator. Example- 1.Write the query to find the id,name,address of employee whose address is Lucknow. Query- select ID,Name,Address from employee where address='Lucknow'; Output- Number of Records: 2 ID Name address 4 Aman Lucknow 5 Hari Lucknow 2.Write the query to retrieve employees details whose salary is more than 10000 and less than 50000. Query- SELECT * FROM employee where salary>10000 and salary<50000 Output- Number of Records: 1 ID Name email address phone_number salary 5 Hari Hari@gmail.com Lucknow 36756890 15000 3.Write the query to display the id,name and the yearly salary of the employees whose annual salaries are less than 200000. Query-SELECT ID , Name , salary*12 Annual_salary FROM employee where Annual_salary<200000; Output- Number of Records: 2 ID Name Annual_salary 1 sharat 60000 5 Hari 180000 4.Write the query to display the id,name and the yearly salary of the employees and also label the column heading id as Emp_Id,name as Employee Name and salary as Yearly Salary Package. Query- SELECT ID as Emp_Id, Name as "Employee Name", salary*12 as "Yearly Salary Package" FROM employee; Output- Number of Records: 5 Emp_Id Employee Name Yearly Salary Package 1 sharat 60000 2 Ajay 612000 3 Amit 612000 4 Aman 612000 5 Hari 180000
Wednesday, March 15, 2017
WHERE Clause-To limit the retrieval of the data from the database for given condition
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment