I am storing the user activity in the table by start and end time , now i want to get all records from my subject table and matched records from log table.
I want the output like this
I tried using some code but the records that only matched with log table is return as record, This is what i tried. Any help is appreciable.
SELECT SUM(TIMESTAMPDIFF(MINUTE, A.start_time, A.end_time)) AS prep_time, B.subject_name, A.subject_id FROM prep_learn_log A RIGHT JOIN prep_subject B ON A.subject_id = B.subject_id AND B.active = 'Y' WHERE A.user_id = '1' GROUP BY A.subject_id