Reputation: 540
I need help counting the number of job types (CLERK, analyst etc). I have written some code but it doesnt return what I want it to. Could anyone suggest whats wrong? Thanks - Jay
SELECT COUNT(*)
FROM emp e, emp d
WHERE e.job = d.job;
Upvotes: 0
Views: 3869
Reputation: 9
If all you need is the number of job types in the table, this simple query will do it:
SELECT COUNT(DISTINCT Job) from emp
Upvotes: -2
Reputation: 56779
You need a GROUP BY clause to inform MySql what different things you want to count. In this case, you want to count unique job values:
SELECT
job,
Count(job)
FROM
emp e
GROUP BY
job
Demo: http://sqlize.com/lfA2Z9nagw
Upvotes: 3