SQL and RDBMS DBA Interview Questions

Suppose you have a database with two tables, employee and department (see below for exact schema). Write a SQL statement to answer the following questions:

  1. Show a list of all employees that includes both the employee name and the department name.
  2. Show a list of departments and include the number of employees in each department.
  3. Show a list of all departments with no employees.
  4. Show a list of departments with more than 2 employees
  5. Show a list of departments that includes average and maximum salary in that department. Sort the list by the average salary.
Employee Table
---------------------
id
first_name
last_name
salary
department

Department Table
-----------------------
id
name