-
-
Save anonymous/ef30a9c590bf51c0bff7 to your computer and use it in GitHub Desktop.
This file contains 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
clocks: shift_id | |
shifts: employee_id | |
employee: name | |
hierarchies: inferior_id, superior_id (both link to employee) | |
Want to only return clocks whose associated employee has a hierarchy | |
where their id matches the inferior_id and the superior_id matches 4 | |
or the associated employee's id is 4 | |
SELECT "clocks".* FROM "clocks" | |
INNER JOIN "shifts" ON "shifts"."id" = "clocks"."shift_id" | |
INNER JOIN "employees" ON "employees"."id" = "shifts"."employee_id" | |
INNER JOIN "hierarchies" ON "hierarchies"."inferior_id" = "employees"."id" | |
INNER JOIN "employees" "superiors_employees" ON "superiors_employees"."id" = "hierarchies"."superior_id" | |
WHERE (hierarchies.superior_id = 3 OR employees.id = 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment