I am trying to separate table results into those who are present and absent. For example, I have this users table here and user_attendance table here. Those users in the user_attendance table were present and I am trying to use the query below to show those who are not present/absent in the user_attendance table:
SELECT *
FROM `user_attendance`
INNER JOIN users on users.user_id = user_attendance.user_id
WHERE users.user_id IS NULL;
Help would be greatly appreciated. Thank you.
CodePudding user response:
--Absent
SELECT *
FROM `users`
WHERE NOT EXISTS (SELECT 1 FROM user_attendance WHERE user_attendance.user_id = users.user_id);
CodePudding user response:
select *
from users
where user_id not in(select user_id from user_attendance where user_id is not null)
user_id | user_name |
---|---|
2 | john |
4 | jose |