let's try this query
SELECT COUNT(abs.id) as AbsenceCount , dept.deptStringName
FROM Absences abs
JOIN Users u on u.id = abs.user_id
JOIN Departments dept on dept.id= u.dept_id
group by dept.deptStringName
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have three tables:
I am trying to figure out Absences per Department. I know I need two inner joins, but at the moment I am confused about how to insert a count in two inner joins using the Laravel Query Builder syntax.
The eventual result could be like:
+-------+---+
| DeptA | 3 |
| DeptF | 7 |
| DeptH | 3 |
| DeptT | 7 |
| DeptZ | 5 |
+-------+---+
let's try this query
SELECT COUNT(abs.id) as AbsenceCount , dept.deptStringName
FROM Absences abs
JOIN Users u on u.id = abs.user_id
JOIN Departments dept on dept.id= u.dept_id
group by dept.deptStringName
Please or to participate in this conversation.