ใช้ UNION ALL รวมข้อมูลทั้งสองตาราง แล้ว GROUP BY ทุกคอลัมน์ กรอง HAVING COUNT(*) = 1 จะได้แถวที่อยู่ในตารางใดตารางหนึ่งอย่างเดียว (symmetric difference) ตัวอย่างตาราง students (3 แถว) และ student1 (5 แถว):
mysql> Select RollNo,Name,Subject from(select RollNo,Name,Subject from students union all select RollNo,Name,Subject from Student1)as std GROUP BY RollNo,Name,Subject HAVING Count(*) = 1 ORDER BY RollNo; +--------+-------+---------+ | RollNo | Name | Subject | +--------+-------+---------+ | 103 | Rahul | DBMS | | 104 | Aarav | History | +--------+-------+---------+ 2 rows in set (0.02 sec)
พบ 2 แถวที่อยู่ใน student1 เท่านั้น (103, 104)