ASP DOT NET

Friday, January 25, 2019

Q. Most Popular SQL Server Interview Questions and Answer?

1. Return Employee Records with Max salary

Ans.
        Select * from employee where salary=(select max(salary) from employee)
2. Return Highest salary in employee table

Ans. 
      Select max(salary) from employee
3. Return second highest salary in employee table 

Ans.
     select max(salary) from employee where salary not in (select max(salary) from employee) 
4. Return range of employee based on id

Ans.
     select * from employee where employee_id between 2003 and 2008
5. Return Employee Name,Highest salary and Departments 

Ans.
     select e.first_name,e.last_name,e.salary,d.department_name from employee e inner join department d on e.department_id=d.department_id where e.salary in(select max(salary) from employee)
6. Return highest salary ,employee_name,department_name for each department 

Ans.
     Select e.first_name,e.last_name,e.salary,d.department_name from employee e inner join department d on e.department_id=d.department_id where salary IN(select max(salary) from employee group by department_id )



No comments:

Post a Comment

How to to select duplicate rows from sql server?

 SELECT * FROM Recruitment WHERE Email IN (SELECT Email FROM Recruitment GROUP BY Email HAVING COUNT(*) > 1); WITH CTE AS (     SELECT   ...