Databases SQL Reporting by Example Day 2: Advanced Selecting Day 2: Review

Steve Rogers
Steve Rogers
2,282 Points

Counting issue?

I tried

ORDER BY role

to answer this question. I'm confused. Any ideas?

Write a query to figure out how many employees are in each job role.

SELECT JOBS.ROLE, COUNT(1) FROM EMPLOYEES JOIN JOBS ON EMPLOYEES.JOB_ID = JOBS.ID ORDER BY role;

1 Answer

Steven Parker
Steven Parker
176,634 Points

The question isn't asking for any particular order, but to associate the counts with the roles you might need to use GROUP BY.

Also, without knowing the exact contents of both tables, it would be safer to refer to column(s) the same way they are referenced in the SELECT clause.