In MySQL I wrote the following query. Making it reselect all that data again using JOIN does not seem the most effective way to me. How would you rewrite it to make it more efficient?
SELECT * FROM (
SELECT COUNT(*) AS 'total' FROM `the_table`
WHERE `subject_id`=7 ) a
JOIN (
SELECT COUNT(*) AS 'unread' FROM `the_table`
WHERE `subject_id`=7 AND `read`=0 ) b
EDIT:
I’m trying to get a table with 2 columns: ‘total’ and ‘unread’ with a single row having INT values, such as
total: 200 unread: 20
Since the where clause is the same except for the condition on read you can use SUM/CASE