SELECT * FROM samak_all LEFT JOIN register_all ON samak_all.id_student=register_all.id_student WHERE register_all.id_student IS NULL OR (samak_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>"1") AND ((SELECT COUNT(*) FROM samak_all WHERE samak_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>"1"))!=(SELECT COUNT(*) FROM register_all WHERE register_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>"1")))) GROUP BY samak_all.id_student
SELECT samak_all.id_student
FROM samak_all LEFT JOIN register_all ON samak_all.id_student=register_all.id_student
WHERE register_all.id_student IS NULL
OR (samak_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>1)
AND (
(SELECT COUNT(*) FROM samak_all
WHERE samak_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>1))
<>
(SELECT COUNT(*) FROM register_all
WHERE register_all.id_student =(SELECT id_student FROM samak_all GROUP BY id_student HAVING COUNT(id_student)>1))
)
)
GROUP BY samak_all.id_student;