Skip to content

Instantly share code, notes, and snippets.

@mzalazar
Created April 1, 2019 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzalazar/86abca876e8d66cb78d66e5b41688dc4 to your computer and use it in GitHub Desktop.
Save mzalazar/86abca876e8d66cb78d66e5b41688dc4 to your computer and use it in GitHub Desktop.
/* Database table install instructions */
https://dev.mysql.com/doc/employee/en/employees-installation.html
/* Return employee record with max salary */
SELECT *
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee)
/* Select highest salary in employee table */
SELECT MAX(salary)
FROM employee
/* Select 2nd highest salary in employee table */
SELECT MAX(salary)
FROM employee
WHERE salary NOT IN(SELECT MAX(salary) FROM employee)
/* select range of employees based on id */
SELECT *
FROM employee
WHERE employee_id BETWEEN 2003 AND 2008
/* Return employee name, highest salary and department */
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)
/* Return highest salary, employee name, department name for each department */
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment