SELECT count(*) AS co FROM todo WHERE EXISTS ( SELECT * FROM user_todo_send uts WHERE uts.id_todo = todo.id AND uts.id_user = $id_user ) OR EXISTS ( SELECT * FROM todo_task_send ts WHERE ts.id_todo = todo.id AND ts.id_user_to = $id_user ) AND todo.confirm = 1 It is necessary to obtain data from one table ( todo ), but so that the ID is the other two tables.
The request works, but EXPLAIN issues:
