Saturday 4 April 2015

SQL Queries Interview Questions and Answers

SQL Queries Interview Questions and Answers:

 "SQL Select"




1. Get all employee details from the employee table
 Select * from employee 
2. Get First_Name,Last_Name from employee table
 Select first_name, Last_Name from employee 
3. Get First_Name from employee table using alias name “Employee Name”
 Select first_name Employee Name from employee 
4. Get First_Name from employee table in upper case
 Select upper(FIRST_NAME) from EMPLOYEE 
5. Get First_Name from employee table in lower case
Select lower(FIRST_NAME) from EMPLOYEE
6. Get unique DEPARTMENT from employee table
select distinct DEPARTMENT from EMPLOYEE
7. Get FIRST_NAME from employee table after removing white spaces from right side
select RTRIM(FIRST_NAME) from employee
8. Get FIRST_NAME from employee table after removing white spaces from left side
select LTRIM(FIRST_NAME) from employee
9. Get First_Name from employee table after replacing 'o' with '$'
select REPLACE(FIRST_NAME,'o','$') from employee

"SQL Where Condition" Interview Questions:

1. Get employee details from employee table whose employee name is “John”
Select * from EMPLOYEE where FIRST_NAME='John'
2. Get employee details from employee table whose employee name are “John” and “Roy”
Select * from EMPLOYEE where FIRST_NAME in ('John','Roy')
3. Get employee details from employee table whose employee name are not “John” and “Roy”
Select * from EMPLOYEE where FIRST_NAME not in ('John','Roy')

"SQL Wild Card Search" Interview Questions:

1. Get employee details from employee table whose first name starts with 'J'
Select * from EMPLOYEE where FIRST_NAME like 'J%'
2. Get employee details from employee table whose first name contains 'o'
Select * from EMPLOYEE where FIRST_NAME like '%o%'
3. Get employee details from employee table whose first name ends with 'n'
Select * from EMPLOYEE where FIRST_NAME like '%n'

"SQL Pattern Matching" Interview Questions:

1. Get employee details from employee table whose first name ends with 'n' and name contains 4 letters
Select * from EMPLOYEE where FIRST_NAME like '___n' (Underscores)
2. Get employee details from employee table whose first name starts with 'J' and name contains 4 letters
Select * from EMPLOYEE where FIRST_NAME like 'J___' (Underscores)
3. Get employee details from employee table whose Salary greater than 600000
Select * from EMPLOYEE where Salary >600000
4. Get employee details from employee table whose Salary less than 800000
Select * from EMPLOYEE where Salary <800000
5. Get employee details from employee table whose Salary between 500000 and 800000
Select * from EMPLOYEE where Salary between 500000 and 800000
6. Get employee details from employee table whose name is 'John' and 'Michael'
Select * from EMPLOYEE where FIRST_NAME in ('John','Michael')

"SQL Group By Query" Interview Questions and Answers:

1. Get department,total salary with respect to a department from employee table.
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by department
2. 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

SQL Queries Interview Questions and Answers on "SQL Mathematical Operations using Group By":

1. Get department,no of employees in a department,total salary with respect to a department from employee table order by total salarydescending
Select DEPARTMENT,count(FIRST_NAME),sum(SALARY) Total_Salary from employee group by DEPARTMENT order by Total_Salary descending
2. Get department wise average salary from employee table order by salaryascending
select DEPARTMENT,avg(SALARY) AvgSalary from employee group by DEPARTMENT order by AvgSalary asc
3. Get department wise maximum salary from employee table order by salaryascending
select DEPARTMENT,max(SALARY) MaxSalary from employee group by DEPARTMENT order by MaxSalary asc
4. Get department wise minimum salary from employee table order by salary ascending
select DEPARTMENT,min(SALARY) MinSalary from employee group by DEPARTMENT order by MinSalary asc
5. Select department,total salary with respect to a department from employee table where total salary greater than 800000 order by Total_Salary descending
Select DEPARTMENT,sum(SALARY) Total_Salary from employee group by DEPARTMENT having sum(SALARY) >800000 order by Total_Salary desc

No comments:

Post a Comment