चूंकि हम MySQL में MINUS क्वेरी का उपयोग नहीं कर सकते, हम JOIN का उपयोग करके MINUS क्वेरी को सिमुलेट करेंगे। इसे निम्न उदाहरण से समझा जा सकता है -
उदाहरण
इस उदाहरण में, हम दो टेबल Student_detail और Student_info ले रहे हैं जिनमें निम्न डेटा है -
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 | +-----------+---------+------------+------------+ 7 rows in set (0.00 sec) 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 | +-----------+-----------+------------+-------------+ 6 rows in set (0.00 sec)
अब, JOIN का उपयोग करने वाली निम्न क्वेरी MINUS को सिमुलेट करेगी ताकि student_info में मौजूद लेकिन Student_detail में नहीं मौजूद 'studentid' मान लौटाए जाएं।
mysql> SELECT studentid from student_info LEFT JOIN Student_detail USING(studentid) WHERE student_detail.studentid IS NULL; +-----------+ | studentid | +-----------+ | 165 | +-----------+ 1 row in set (0.07 sec)
अब, निम्न क्वेरी हमें उपरोक्त क्वेरी का विपरीत परिणाम देगी यानी यह student_detail में मौजूद लेकिन Student_info में नहीं मौजूद 'studentid' मान लौटाएगी।
mysql> SELECT studentid from student_detail LEFT JOIN Student_info USING(studentid) WHERE student_info.studentid IS NULL; +-----------+ | studentid | +-----------+ | 150 | | 160 | +-----------+ 2 rows in set (0.00 sec)