Trying to get two different counts in one query. To do this I am selecting from a table and need to join another one. Check out the (not working) queries below. These were different ways I was trying to do it - unsuccessfully.
Is this possible, and if so can you offer assistance getting a working query?
SELECT
count( tasks_assigned.task_id ) AS task_assigned_count,
count( tasks_created.task_id ) AS task_created_count,
FROM projects
LEFT JOIN tasks AS tasks_assigned
ON tasks_assigned.project_id = projects.project_id
AND tasks_assigned.assigned_user_id = 1
LEFT JOIN tasks AS tasks_created
ON tasks_created.project_id = projects.project_id
AND tasks_created.created_user_id = 1
GROUP BY tasks_assigned.project_id, tasks_created.project_id
SELECT
projects.*
, (SELECT count(task_id) as task_assigned_count FROM tasks as task_assigned WHERE task_assigned.project_id = projects.project_id AND assigned_user_id = 1 GROUP BY task_id) as task_assigned_count
, (SELECT count(task_id) as task_created_count FROM tasks as task_created WHERE task_created.project_id = projects.project_id AND assigned_user_id = 1 GROUP BY task_id) as task_assigned_count
FROM projects