CREATE VIEW `tgb_view_groups_members` AS SELECT t2.id, t2.group_name, t2.chat_id as owner_id, t1.chat_id, t1.invite_time, t3.first_name, t3.last_name, t3.username FROM `tgb_workaround_members` as t1 LEFT JOIN `tgb_workaround` as t2 ON t2.id=t1.group_id LEFT JOIN `tgb_profiles` as t3 ON t1.chat_id = t3.chat_id CREATE VIEW `tgb_view_tasks_by_user` AS SELECT t1.*, t2.chat_id as group_owner_id, t2.group_name, t3.first_name, t3.last_name, t4.first_name as owner_first_name, t4.last_name as owner_last_name, IF (t1.deadline < CURRENT_TIMESTAMP, 1, 0) as expired, t5.notify FROM `tgb_tasks` as t1 LEFT JOIN `tgb_workaround` as t2 ON t1.group_id=t2.id LEFT JOIN `tgb_profiles` as t3 ON t1.member_id=t3.chat_id LEFT JOIN `tgb_profiles` as t4 ON t1.owner_id=t4.chat_id LEFT JOIN `tgb_expire_notify` as t5 ON t1.id=t5.task_id AND t5.member_id=t1.member_id CREATE VIEW tgb_view_task_withcomments as SELECT t1.*, t2.comment_time, t2.chat_id, t2.description as comment FROM `tgb_tasks` as t1 LEFT JOIN `tgb_tasks_comments` as t2 ON t1.id=t2.task_id