SQL Query Exercise
SQL Query Exercise
5. Get all employee details from the employee table order by First_Name Ascending
Select * from employee order by FIRST_NAME asc
16. Get all employee details from the employee table order by First_Name descending
17. Get all employee details from the employee table order by First_Name Ascending
and Salary descending
Select * from employee order by FIRST_NAME asc,SALARY desc
"SQL Where Condition"
18. Get employee details from employee table whose employee name is “John”
Select * from EMPLOYEE where FIRST_NAME='John'
19. Get employee details from employee table whose employee name are “John” and
“Roy”
Select * from EMPLOYEE where FIRST_NAME in ('John','Roy')
20. Get employee details from employee table whose employee name are not “John” and
“Roy”
Select * from EMPLOYEE where FIRST_NAME not in ('John','Roy')
22. Get employee details from employee table whose first name contains 'o'
23. Get employee details from employee table whose first name ends with 'n'
24. Get employee details from employee table whose first name ends with 'n' and name
contains 4 letters
25. Get employee details from employee table whose first name starts with 'J' and name
contains 4 letters
26. Get employee details from employee table whose Salary greater than 600000
28. Get employee details from employee table whose Salary between 500000 and 800000
29. Get employee details from employee table whose name is 'John' and 'Michael'
33. Get employee details from employee table who joined after January 31st
SQL Queries in Oracle, Select * from EMPLOYEE where JOINING_DATE
>to_date('31/01/2013','dd/mm/yyyy')
SQL Queries in SQL Server and MySQL (Format - “MM/DD/YYYY”), Select * from
EMPLOYEE where joining_date >'01/31/2013'
Get names of employees from employee table who has '%' in Last_Name. Tip : Escape
character for special characters in a query.
SQL Queries in Oracle, Select FIRST_NAME from employee where Last_Name like
'%?%%'
SQL Queries in SQL Server, Select FIRST_NAME from employee where Last_Name
like '%[%]%'
SQL Queries in MySQL, Select FIRST_NAME from employee where Last_Name like
'%\%%'
40. Get Last Name from employee table after replacing special character with white
space
SQL Queries in Oracle, Select translate(LAST_NAME,'%',' ') from employee
SQL Queries in SQL Server and MySQL, Select REPLACE(LAST_NAME,'%',' ') from
employee
42. Get department,total salary with respect to a department from employee table order
by total salary descending
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by
DEPARTMENT order by Total_Salary descending
44. Get department wise average salary from employee table order by salary ascending
45. Get department wise maximum salary from employee table order by salary
ascending
46. Get department wise minimum salary from employee table order by salary
ascending
47. Select no of employees joined with respect to year and month from employee table
48. Select department,total salary with respect to a department from employee table
where total salary greater than 800000 order by Total_Salary descending
Insert into employee table Last Name with " ' " (Single Quote - Special Character)
Tip - Use another single quote before special character
Insert into employee (LAST_NAME) values ('Test''')