select t1.*, t2.in, t2.out, t2.move, t1.all + t2.in-t2.out-t2.move as endofday
from tab1 as t1 /*Дата | Проект | Кол-во сотрудников*/
join tab2 as t2 /*Дата | Проект | Пришло | Ушло | Перевелось*/
on t1.data = t2.data and t1.project = t2.project
SELECT m.`id`, m.`message`, case when mr.`message_id` is not null then 'Прочитано' else 'Не прочитано' end as iRead
FROM `messages` m
LEFT JOIN `messages_read` mr ON mr.`message_id` = m.`id`
WHERE m.`chat_id` = 12 and AND mr.`user_id` = 111