Created
December 5, 2017 21:07
-
-
Save johnhonan/a73bf5c0e5050619a88f74f0c9cf7482 to your computer and use it in GitHub Desktop.
Joining subqueries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT | |
job_history.employee_id, | |
employees.first_name, | |
x.max_start, | |
y.min_start | |
FROM hr.job_history | |
JOIN hr.employees | |
ON job_history.employee_id = employees.employee_id | |
JOIN | |
(SELECT employee_id, max(start_date) as max_start | |
FROM hr.job_history | |
GROUP BY employee_id) x | |
ON job_history.employee_id = x.employee_id | |
JOIN (SELECT employee_id, min(start_date) as min_start | |
FROM hr.job_history | |
GROUP BY employee_id) y | |
ON job_history.employee_id = y.employee_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment