← Back to MySQL Course | Chapter 6: Filtering & Sorting | Lesson 2 of 8

AND OR NOT Operators

AND, OR और NOT एक snack चुनते समय इस्तेमाल होने वाले words जैसे हैं: यह भी और वह भी, यह या वह, या इसे छोड़कर कुछ भी।
Syntax
sql
WHERE condition1 AND condition2
WHERE condition1 OR condition2
WHERE NOT condition

AND Operator

AND कई conditions को इस तरह combine करता है कि किसी row को results में दिखने के लिए हर एक true होनी ज़रूरी है, आपको ज़्यादा clauses add करते हुए एक search को बढ़ती precision के साथ narrow करने देते हुए।

उदाहरण: The AND Operator

sql
SELECT * FROM users WHERE age > 18 AND city = 'Patna';

OR Operator

OR को combined conditions में से सिर्फ एक के true होने की ज़रूरत है, जो search को narrow करने के बजाय broaden करता है — तब उपयोगी जब आपको कई acceptable criteria में से किसी से match करने वाली rows चाहिए हों।

उदाहरण: The OR Operator

sql
SELECT * FROM users WHERE city = 'Patna' OR city = 'Delhi';

NOT Operator

NOT जो भी condition उसके बाद आती है उसे invert कर देता है, वे rows return करते हुए जहाँ वह condition false हो — 'everyone except inactive users' जैसे exclusions को एक negative comparison से ज़्यादा naturally express करने के लिए handy।

उदाहरण: The NOT Operator

sql
SELECT * FROM users WHERE NOT status = 'inactive';

AND को OR के साथ Combine करना

जब AND और OR same WHERE clause में साथ दिखें, OR conditions को parentheses में wrap करना ज़रूरी है, क्योंकि MySQL AND को ज़्यादा precedence से evaluate करता है और अन्यथा unexpectedly conditions group कर सकता है।

उदाहरण: Combining AND with OR

sql
SELECT * FROM users WHERE city = 'Patna' AND (age > 18 OR status = 'verified');

NOT को दूसरे Filters के साथ Combine करना

NOT एक ही बार में conditions के पूरे parenthesized group को भी wrap कर सकता है, आपको सिर्फ एक single simple comparison negate करने के बजाय एक पूरी compound match exclude करने देते हुए।

उदाहरण: Combining NOT with other filters

sql
SELECT * FROM users WHERE NOT (city = 'Patna' AND age > 18);
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. बिना parentheses के AND और OR mix करना, ताकि AND पहले evaluate हो और result वह न हो जो आप मतलब रखते थे।
  2. WHERE city = Patna OR Delhi लिखना, जो Delhi के साथ एक comparison नहीं है।
  3. column के बजाय condition से पहले NOT इस्तेमाल करना, जैसे WHERE NOT city = Patna गलत पढ़ा गया, <> या clear parentheses के बजाय।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.