MySQL MINUS (या EXCEPT) ऑपरेटर सपोर्ट नहीं करता, लेकिन LEFT JOIN ... WHERE IS NULL पैटर्न से समान परिणाम प्राप्त कर सकते हैं। यह "पहली टेबल में मौजूद लेकिन दूसरी में नहीं" वाली पंक्तियाँ ढूंढता है।
उदाहरण: दो छात्र टेबल्स
Student_detail (7 पंक्तियाँ) और Student_info (6 पंक्तियाँ):
mysql> SELECT * FROM Student_detail;
+-----------+---------+------------+------------+
| studentid | Name | Address | Subject |
+-----------+---------+------------+------------+
| 101 | YashPal | Amritsar | History |
| 105 | Gaurav | Chandigarh | Literature |
| 130 | Ram | Jhansi | Computers |
| 132 | Shyam | Chandigarh | Economics |
| 133 | Mohan | Delhi | Computers |
| 150 | Rajesh | Jaipur | Yoga |
| 160 | Pradeep | Kochi | Hindi |
+-----------+---------+------------+------------+
mysql> SELECT * FROM Student_info;
+-----------+-----------+------------+-------------+
| studentid | Name | Address | Subject |
+-----------+-----------+------------+-------------+
| 101 | YashPal | Amritsar | History |
| 105 | Gaurav | Chandigarh | Literature |
| 130 | Ram | Jhansi | Computers |
| 132 | Shyam | Chandigarh | Economics |
| 133 | Mohan | Delhi | Computers |
| 165 | Abhimanyu | Calcutta | Electronics |
+-----------+-----------+------------+-------------+
क्वेरी 1: Student_info में है लेकिन Student_detail में नहीं
mysql> SELECT studentid
FROM student_info
LEFT JOIN Student_detail USING(studentid)
WHERE student_detail.studentid IS NULL;
+-----------+
| studentid |
+-----------+
| 165 |
+-----------+
क्वेरी 2: Student_detail में है लेकिन Student_info में नहीं
mysql> SELECT studentid
FROM student_detail
LEFT JOIN Student_info USING(studentid)
WHERE student_info.studentid IS NULL;
+-----------+
| studentid |
+-----------+
| 150 |
| 160 |
+-----------+
पैटर्न समझ
SELECT t1.कॉलम
FROM टेबल1 t1
LEFT JOIN टेबल2 t2 ON t1.कुंजी = t2.कुंजी
WHERE t2.कुंजी IS NULL;
यह टेबल1 - टेबल2 (MINUS) के बराबर है।
बहु-कॉलम तुलना के लिए
SELECT t1.*
FROM टेबल1 t1
LEFT JOIN टेबल2 t2
ON t1.col1 = t2.col1 AND t1.col2 = t2.col2 ...
WHERE t2.col1 IS NULL;