This gives me errors. How do I need to rewrite it?
I want to have the query return both the subject and that row's corresponding count.
SELECT (SELECT subject FROM marks) AS subject, (SELECT count FROM marks) AS count WHERE usr = 'username'
This gives me errors. How do I need to rewrite it?
I want to have the query return both the subject and that row's corresponding count.
SELECT (SELECT subject FROM marks) AS subject, (SELECT count FROM marks) AS count WHERE usr = 'username'
The subqueries are not required and are breaking your relationship. Try this:
SELECT subject, `count` FROM marks WHERE usr = 'username';
I think count
is a column in your table? If so, as @TedHopp points out, since count
is also a mysql built-in function, you'll have to escape it to refer to the column name.
http://sqlfiddle.com/#!9/e3cd1/1 is a corresponding fiddle.
SELECT subject, COUNT(subject) `count`
FROM marks
WHERE usr = 'username'
GROUP BY subject