SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL Notes in Hindi & English : SQL लॉजिकल ऑपरेटर्स: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL (SQL लॉजिकल ऑपरेटर्स: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: SQL logical operators (AND, OR, NOT) combine conditions following strict NOT > AND > OR precedence, while BETWEEN, IN, LIKE, and IS NULL handle ranges, sets, patterns, and nulls cleanly.

अध्याय सार: SQL लॉजिकल ऑपरेटर्स (AND, OR, NOT) NOT > AND > OR प्राथमिकता क्रम से शर्तों को जोड़ते हैं, जबकि BETWEEN, IN, LIKE और IS NULL क्रमशः रेंज, सेट, पैटर्न और NULL जांच को सरल बनाते हैं।

SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL: Detailed Notes & Architecture (SQL लॉजिकल ऑपरेटर्स: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL)

1. Boolean Operators (AND, OR, NOT) and Precedence Rules (बूलियन ऑपरेटर्स (AND, OR, NOT) और प्राथमिकता नियम)

[EN] AND requires every joined predicate to be TRUE, OR passes if at least one predicate is TRUE, and NOT inverts TRUE to FALSE (and FALSE to TRUE). Crucially, SQL evaluates NOT first, then AND, and finally OR. Writing `WHERE Dept='IT' OR Dept='CS' AND Sal > 50000` pairs `Dept='CS' AND Sal > 50000` first and returns ALL 'IT' staff regardless of salary—always wrap OR conditions in parentheses! Under 3VL, `TRUE OR UNKNOWN` yields TRUE and `FALSE AND UNKNOWN` yields FALSE, whereas `NOT UNKNOWN` remains UNKNOWN.

[HI] AND में सभी शर्तों का सत्य होना जरूरी है, OR में किसी एक शर्त का सत्य होना पर्याप्त है, और NOT परिणाम को उलट देता है। SQL में प्राथमिकता क्रम NOT > AND > OR होता है। यदि बिना कोष्ठक के `Dept='IT' OR Dept='CS' AND Sal > 50000` लिखें, तो AND पहले जुड़ने से सभी 'IT' कर्मचारी आ जाएंगे—अतः OR के लिए कोष्ठक () लगाना जरूरी है। 3VL में TRUE OR UNKNOWN = TRUE और FALSE AND UNKNOWN = FALSE होता है।

2. Inclusive Range Filtering with BETWEEN ... AND ... (BETWEEN ... AND ... द्वारा समावेशी रेंज फ़िल्टरिंग)

[EN] The `col BETWEEN low AND high` operator tests an inclusive closed interval equivalent to `(col >= low AND col <= high)`, including both endpoint boundaries. It operates seamlessly on numbers, strings, and dates; however, the lower bound MUST come first—writing `BETWEEN 50 AND 10` matches zero rows because `col >= 50 AND col <= 10` is impossible. Beware of DATETIME timestamps: `BETWEEN '2025-01-01' AND '2025-01-31'` converts `'2025-01-31'` to midnight (`00:00:00`), missing transactions later that day.

[HI] `col BETWEEN low AND high` एक समावेशी (Inclusive) रेंज जांचता है जो `(col >= low AND col <= high)` के समतुल्य है—अर्थात दोनों सीमांत मान शामिल होते हैं। इसमें हमेशा छोटा मान पहले और बड़ा मान बाद में आना चाहिए; `BETWEEN 50 AND 10` शून्य पंक्तियाँ देगा। DATETIME कॉलम में `BETWEEN '2025-01-01' AND '2025-01-31'` अंतिम दिन की केवल 00:00:00 बजे तक की ही प्रविष्टियाँ पकड़ता है।

3. Set Membership with IN / NOT IN and the NULL Subquery Trap (IN / NOT IN ऑपरेटर और NULL का छिपा खतरा)

[EN] The `IN (v1, v2, v3)` operator cleanly replaces lengthy OR chains (`col = v1 OR col = v2 OR col = v3`) and also accepts single-column subqueries. However, `NOT IN` contains a famous SQL exam trap: if the list or subquery contains even ONE NULL value, `col NOT IN (10, NULL)` expands to `col <> 10 AND col <> NULL`, which evaluates to UNKNOWN for every row and returns an EMPTY result set! Filtering NULLs out of the subquery or using `NOT EXISTS` prevents this bug.

[HI] `IN (v1, v2, v3)` कई OR शर्तों का संक्षिप्त रूप है और सबक्वेरी के साथ भी चलता है। परंतु `NOT IN` में एक प्रसिद्ध खतरा है: यदि सूची या सबक्वेरी में एक भी NULL मान मौजूद हो, तो `col NOT IN (10, NULL)` का विस्तार `col <> 10 AND col <> NULL` होकर हर पंक्ति के लिए UNKNOWN देता है और परिणाम खाली (0 पंक्तियाँ) आ जाता है! इसे रोकने हेतु सबक्वेरी में `IS NOT NULL` या `NOT EXISTS` उपयोग करें।

4. Pattern Matching (LIKE) and Missing-Value Testing (IS NULL) (LIKE पैटर्न मिलान तथा IS NULL जांच)

[EN] LIKE evaluates wildcard string matching using `%` (zero or more characters) and `_` (one character), while `IS NULL` and `IS NOT NULL` provide the sole standard mechanism to detect missing markers in a table. Related quantified comparison operators `= ANY (...)` behave identically to `IN (...)`, whereas `<> ALL (...)` behaves identically to `NOT IN (...)`. Combining these operators in clean parenthesized expressions ensures unambiguous query logic.

[HI] LIKE ऑपरेटर `%` व `_` वाइल्डकार्ड्स से टेक्स्ट पैटर्न मिलाता है, जबकि `IS NULL` और `IS NOT NULL` डेटाबेस में अनुपस्थित मान (NULL) जांचने का एकमात्र मानक तरीका हैं। इसी प्रकार `= ANY (...)` बिल्कुल `IN` की तरह तथा `<> ALL (...)` बिल्कुल `NOT IN` की तरह कार्य करता है। सही कोष्ठकों के साथ इनका संयोजन सटीक परिणाम देता है।

Syntax, Formula & Technical Example (SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL)

-- Parentheses prevent AND from binding tighter than OR
SELECT EmpID, Name, Dept, Salary
FROM Employees
WHERE (Dept = 'IT' OR Dept = 'Data')
  AND Salary BETWEEN 40000 AND 90000
  AND City IN ('Jaipur', 'Kota', 'Udaipur')
  AND Name LIKE 'A%'
  AND ResignDate IS NULL;

SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL Quick Reference & Comparison Table

Logical OperatorEvaluation Semantics & BoundaryCritical Exam Trap
AND / OR / NOTCombines predicates; precedence order is NOT > AND > ORAlways parenthesize OR mixed with AND; TRUE OR UNKNOWN = TRUE
BETWEEN low AND highInclusive range check: col >= low AND col <= highReversed bounds (BETWEEN 100 AND 10) return 0 rows
IN / NOT INTests membership against value list or single-column subqueryNOT IN returns 0 rows if list/subquery contains any NULL
IS NULL / IS NOT NULLUnambiguously tests absence or presence of SQL NULL markerMust use IS NULL instead of '= NULL'; LIKE also skips NULLs

SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL Top 20 Bilingual MCQs with Answers

Q1. What is the strict operator precedence order among SQL logical operators AND, OR, and NOT (highest to lowest)?

(SQL लॉजिकल ऑपरेटर्स NOT, AND और OR की प्राथमिकता (उच्चतम से निम्नतम) का सही क्रम क्या है?)

(A) AND > OR > NOT

(B) NOT > AND > OR

(C) Left-to-right with equal precedence

(D) OR > AND > NOT

Correct Answer: (B)

[EN] NOT binds tightest, followed by AND, and finally OR; parentheses override any precedence.

[HI] सबसे पहले NOT, फिर AND और अंत में OR हल होता है (NOT > AND > OR)।

Q2. Consider `WHERE Dept = 'HR' OR Dept = 'IT' AND Salary > 60000`. Which employees qualify?

(`WHERE Dept = 'HR' OR Dept = 'IT' AND Salary > 60000` लिखने पर कौन से कर्मचारी चुने जाएंगे?)

(A) Only employees in both HR and IT

(B) No employees because AND precedes OR

(C) ALL HR employees (regardless of salary) plus IT employees earning over 60000

(D) HR and IT employees earning over 60000

Correct Answer: (C)

[EN] Because AND has higher precedence than OR, SQL parses it as `Dept='HR' OR (Dept='IT' AND Salary > 60000)`.

[HI] AND की प्राथमिकता OR से अधिक होने से SQL इसे `Dept='HR' OR (Dept='IT' AND Salary > 60000)` मानकर सभी HR कर्मचारियों को भी चुन लेगा।

Q3. Are the boundary values 10 and 20 included in `WHERE Marks BETWEEN 10 AND 20`?

(क्या `WHERE Marks BETWEEN 10 AND 20` में सीमांत मान 10 और 20 शामिल होते हैं?)

(A) No — BETWEEN is strictly exclusive (11 to 19 only)

(B) Only 10 is included, 20 is excluded

(C) Only 20 is included, 10 is excluded

(D) Yes — BETWEEN is strictly inclusive of both 10 and 20

Correct Answer: (D)

[EN] BETWEEN a AND b translates directly to `>= a AND <= b`, including both endpoints.

[HI] BETWEEN एक समावेशी (Inclusive) ऑपरेटर है जो `>= 10 AND <= 20` के बराबर होता है।

Q4. What does `WHERE Price BETWEEN 500 AND 100` return on a valid table containing prices 100, 250, 500?

(यदि टेबल में कीमतें 100, 250, 500 हों, तो `WHERE Price BETWEEN 500 AND 100` कितनी पंक्तियाँ लौटाएगा?)

(A) 3 rows (SQL auto-swaps bounds)

(B) 2 rows (100 and 500)

(C) SyntaxError

(D) 0 rows (empty result set)

Correct Answer: (D)

[EN] SQL evaluates `Price >= 500 AND Price <= 100`, which is impossible for any number.

[HI] SQL `Price >= 500 AND Price <= 100` की जांच करता है, जो किसी भी संख्या के लिए सत्य नहीं हो सकता—अतः 0 पंक्तियाँ मिलेंगी।

Q5. Suppose Table A has IDs {1, 2, 3} and Subquery B returns {2, NULL}. How many rows return from `SELECT * FROM A WHERE ID NOT IN (SELECT val FROM B)`?

(टेबल A में ID {1, 2, 3} हैं और सबक्वेरी B से {2, NULL} मिलता है। `WHERE ID NOT IN (SELECT val FROM B)` कितनी पंक्तियाँ देगा?)

(A) 1 row (1 only)

(B) 3 rows

(C) 0 rows (empty set)

(D) 2 rows (1 and 3)

Correct Answer: (C)

[EN] 1 NOT IN (2, NULL) becomes (1<>2 AND 1<>NULL) = TRUE AND UNKNOWN = UNKNOWN, filtering out every row!

[HI] NOT IN के भीतर एक भी NULL होने पर सभी पंक्तियों के लिए शर्त UNKNOWN हो जाती है और आउटपुट खाली (0 पंक्तियाँ) आता है।

Q6. In SQL Three-Valued Logic, what do `TRUE OR UNKNOWN` and `FALSE AND UNKNOWN` evaluate to respectively?

(SQL थ्री-वैल्यूड लॉजिक में `TRUE OR UNKNOWN` और `FALSE AND UNKNOWN` का मान क्रमशः क्या होता है?)

(A) FALSE and TRUE

(B) TRUE and FALSE

(C) UNKNOWN and UNKNOWN

(D) TRUE and UNKNOWN

Correct Answer: (B)

[EN] Short-circuit truth: TRUE OR anything = TRUE; FALSE AND anything = FALSE.

[HI] TRUE के साथ OR करने पर परिणाम निश्चित रूप से TRUE, और FALSE के साथ AND करने पर परिणाम निश्चित रूप से FALSE होता है।

Q7. What is the exact equivalent of `WHERE NOT (Marks >= 40 AND Attendance >= 75)` by De Morgan's Law?

(डी-मॉर्गन नियम के अनुसार `WHERE NOT (Marks >= 40 AND Attendance >= 75)` का सटीक समतुल्य क्या है?)

(A) WHERE Marks > 40 OR Attendance > 75

(B) WHERE Marks <= 40 OR Attendance <= 75

(C) WHERE Marks < 40 OR Attendance < 75

(D) WHERE Marks < 40 AND Attendance < 75

Correct Answer: (C)

[EN] Negating (A AND B) yields (NOT A OR NOT B), flipping >= into <.

[HI] NOT (A AND B) = (NOT A OR NOT B), और >= का उल्टा < होता है।

Q8. Which expression is strictly equivalent to `WHERE Age NOT BETWEEN 18 AND 60`?

(`WHERE Age NOT BETWEEN 18 AND 60` का बिल्कुल समतुल्य रूप कौन सा है?)

(A) WHERE Age < 18 OR Age > 60

(B) WHERE Age < 18 AND Age > 60

(C) WHERE Age <> 18 AND Age <> 60

(D) WHERE Age <= 18 OR Age >= 60

Correct Answer: (A)

[EN] Since BETWEEN 18 AND 60 includes 18..60, NOT BETWEEN keeps values strictly below 18 OR strictly above 60.

[HI] BETWEEN में 18 से 60 शामिल हैं, इसलिए NOT BETWEEN में 18 से कम या 60 से अधिक मान आते हैं।

Q9. In SQL Three-Valued Logic, what does `NOT (UNKNOWN)` evaluate to?

(SQL थ्री-वैल्यूड लॉजिक में `NOT (UNKNOWN)` का मान क्या होता है?)

(A) UNKNOWN

(B) NULL error

(C) TRUE

(D) FALSE

Correct Answer: (A)

[EN] Negating an unknown truth value remains unknown.

[HI] अज्ञात (UNKNOWN) सत्य मान को NOT करने पर भी वह UNKNOWN ही रहता है।

Q10. Which quantified predicate is functionally identical to `col IN (SELECT x FROM T)`?

(निम्न में से कौन सा ऑपरेटर `col IN (SELECT x FROM T)` के बिल्कुल समान कार्य करता है?)

(A) col = ANY (SELECT x FROM T)

(B) col <> ANY (SELECT x FROM T)

(C) col = ALL (SELECT x FROM T)

(D) col EXISTS (SELECT x FROM T)

Correct Answer: (A)

[EN] Matching at least one value (= ANY) is identical to set membership IN, while <> ALL equals NOT IN.

[HI] कम से कम एक मान से मिलान (= ANY) बिल्कुल IN के समान होता है।

Q11. How does `WHERE Email IS NULL` differ from `WHERE Email = ''` in ANSI SQL (Oracle excluded)?

(ANSI SQL (Oracle को छोड़कर) में `WHERE Email IS NULL` और `WHERE Email = ''` में क्या अंतर है?)

(A) Email = '' throws an integer error

(B) IS NULL matches spaces ' ' automatically

(C) IS NULL detects absent/undefined markers, whereas '' checks for a zero-length empty string

(D) Both are identical in every database

Correct Answer: (C)

[EN] An empty string '' is a known character value of length 0 (except Oracle VARCHAR2); NULL represents an unknown/missing value.

[HI] '' शून्य लंबाई की एक वैध स्ट्रिंग है, जबकि NULL अनुपस्थित/अज्ञात मान को दर्शाता है (Oracle VARCHAR2 इसका अपवाद है)।

Q12. Why might `WHERE OrderDate BETWEEN '2025-05-01' AND '2025-05-31'` miss an order placed at `'2025-05-31 14:20:00'`?

(DATETIME कॉलम पर `BETWEEN '2025-05-01' AND '2025-05-31'` लिखने पर `'2025-05-31 14:20:00'` वाला ऑर्डर क्यों छूट सकता है?)

(A) DATETIME cannot use BETWEEN

(B) The date literal '2025-05-31' defaults to midnight '2025-05-31 00:00:00', excluding afternoon times

(C) May only has 30 days in SQL calendar

(D) BETWEEN ignores the last day of every month

Correct Answer: (B)

[EN] Use half-open intervals `OrderDate >= '2025-05-01' AND OrderDate < '2025-06-01'` for DATETIME ranges.

[HI] तारीख `'2025-05-31'` को समय के बिना लिखने पर वह मध्यरात्रि `00:00:00` मान ली जाती है, जिससे दोपहर का डेटा छूट जाता है।

Q13. Which SQL operator helps simplify `WHERE State = 'RJ' OR State = 'GJ' OR State = 'MP'`?

(`WHERE State = 'RJ' OR State = 'GJ' OR State = 'MP'` को संक्षिप्त करने के लिए कौन सा ऑपरेटर सबसे उपयुक्त है?)

(A) WHERE State BETWEEN 'RJ' AND 'MP'

(B) WHERE State ALL ('RJ', 'GJ', 'MP')

(C) WHERE State IN ('RJ', 'GJ', 'MP')

(D) WHERE State LIKE ('RJ', 'GJ', 'MP')

Correct Answer: (C)

[EN] IN checks membership in a discrete comma-separated list cleanly.

[HI] असंबद्ध मानों की सूची में मिलान करने हेतु IN ऑपरेटर सबसे सरल है।

Q14. What happens to NULL rows in `WHERE City IN ('Jaipur', 'Ajmer', NULL)`?

(`WHERE City IN ('Jaipur', 'Ajmer', NULL)` चलाने पर जिन पंक्तियों में City स्वयं NULL है, क्या वे लौटेंगी?)

(A) SyntaxError: NULL forbidden inside IN

(B) All rows in the table are returned

(C) Yes — putting NULL inside IN matches NULL rows

(D) No — NULL = NULL yields UNKNOWN, so NULL rows are NOT returned by IN (..., NULL)

Correct Answer: (D)

[EN] Even if NULL is listed inside IN (...), `City = NULL` evaluates to UNKNOWN; you still need `OR City IS NULL`.

[HI] IN सूची में NULL लिख देने से भी NULL पंक्तियाँ नहीं चुनी जातीं क्योंकि NULL = NULL का परिणाम UNKNOWN होता है।

Q15. What does `WHERE Name IS NOT NULL AND Marks NOT IN (0, 100)` filter out?

(`WHERE Name IS NOT NULL AND Marks NOT IN (0, 100)` किसे बाहर रखता है?)

(A) Only rows with Marks 0 or 100 (keeps NULL Marks)

(B) Rows with Marks between 1 and 99

(C) Rows with NULL Name, Marks equal to 0 or 100, and rows where Marks is NULL

(D) Only rows with NULL Name

Correct Answer: (C)

[EN] If Marks is NULL, `NULL NOT IN (0, 100)` evaluates to UNKNOWN and is also excluded!

[HI] Name के NULL होने या Marks के 0, 100 अथवा NULL होने पर पंक्तियाँ बाहर हो जाती हैं।

Q16. Which statement is NOT true about SQL logical operators?

(SQL लॉजिकल ऑपरेटर्स के संदर्भ में कौन सा कथन असत्य (NOT true) है?)

(A) NOT IN returns 0 rows if any element in the subquery is NULL

(B) IS NULL is required because '=' cannot match NULL

(C) BETWEEN includes both the start and end values

(D) OR has higher operator precedence than AND in standard SQL

Correct Answer: (D)

[EN] In standard SQL, AND always binds tighter than OR (NOT > AND > OR).

[HI] मानक SQL में AND की प्राथमिकता OR से अधिक होती है (NOT > AND > OR), न कि OR की।

Q17. Within SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL, which logical operator directly maps to: "Combines predicates; precedence order is NOT > AND > OR"?

(SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL में कौन सा Logical Operator सीधे "Combines predicates; precedence order is NOT > AND > OR" से संबंधित है?)

(A) BETWEEN low AND high

(B) AND / OR / NOT

(C) IS NULL / IS NOT NULL

(D) IN / NOT IN

Correct Answer: (B)

[EN] In SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL, 'AND / OR / NOT' handles 'Combines predicates; precedence order is NOT > AND > OR' (Always parenthesize OR mixed with AND; TRUE OR UNKNOWN = TRUE).

[HI] SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL में 'AND / OR / NOT' का कार्य/विवरण 'Combines predicates; precedence order is NOT > AND > OR' (Always parenthesize OR mixed with AND; TRUE OR UNKNOWN = TRUE) है।

Q18. Which option accurately describes 'BETWEEN low AND high' in SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL?

(SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL के संदर्भ में 'BETWEEN low AND high' की सही विशेषता कौन सी है?)

(A) Inclusive range check: col >= low AND col <= high

(B) Combines predicates; precedence order is NOT > AND > OR

(C) Unambiguously tests absence or presence of SQL NULL marker

(D) Tests membership against value list or single-column subquery

Correct Answer: (A)

[EN] 'BETWEEN low AND high' provides 'Inclusive range check: col >= low AND col <= high' — key point: Reversed bounds (BETWEEN 100 AND 10) return 0 rows.

[HI] 'BETWEEN low AND high' का मुख्य विवरण 'Inclusive range check: col >= low AND col <= high' है (Reversed bounds (BETWEEN 100 AND 10) return 0 rows)।

Q19. In SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL, identify the correct parameter for the specification: "Tests membership against value list or single-column subquery".

(SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL में "Tests membership against value list or single-column subquery" विवरण किस विकल्प के लिए सही है?)

(A) AND / OR / NOT

(B) IN / NOT IN

(C) BETWEEN low AND high

(D) IS NULL / IS NOT NULL

Correct Answer: (B)

[EN] 'IN / NOT IN' corresponds to 'Tests membership against value list or single-column subquery' (NOT IN returns 0 rows if list/subquery contains any NULL).

[HI] 'IN / NOT IN' का संबंध 'Tests membership against value list or single-column subquery' (NOT IN returns 0 rows if list/subquery contains any NULL) से है।

Q20. Considering SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL, what key behavior defines 'IS NULL / IS NOT NULL'?

(SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL में 'IS NULL / IS NOT NULL' की मुख्य भूमिका या मान क्या है?)

(A) Tests membership against value list or single-column subquery

(B) Unambiguously tests absence or presence of SQL NULL marker

(C) Combines predicates; precedence order is NOT > AND > OR

(D) Inclusive range check: col >= low AND col <= high

Correct Answer: (B)

[EN] 'IS NULL / IS NOT NULL' represents 'Unambiguously tests absence or presence of SQL NULL marker' (Must use IS NULL instead of '= NULL'; LIKE also skips NULLs).

[HI] 'IS NULL / IS NOT NULL' का अर्थ/मान 'Unambiguously tests absence or presence of SQL NULL marker' है (Must use IS NULL instead of '= NULL'; LIKE also skips NULLs)।

SQL Logical Operators: AND, OR, NOT, BETWEEN, IN, LIKE, IS NULL — Exam FAQs

Q1: Why should I always put parentheses around OR conditions when combining with AND?

AND के साथ OR मिलाते समय कोष्ठक () लगाना क्यों आवश्यक माना जाता है?

[EN] Because AND has higher precedence than OR. Without parentheses, `A OR B AND C` executes as `A OR (B AND C)` instead of `(A OR B) AND C`, often returning unintended rows.

[HI] क्योंकि SQL में AND की प्राथमिकता OR से ज्यादा है। बिना कोष्ठक के `A OR B AND C` को `A OR (B AND C)` समझा जाता है, जिससे गलत डेटा आ सकता है।

Q2: Why did `NOT IN (subquery)` suddenly return 0 rows even though matches exist?

सबक्वेरी में सही मान होने के बावजूद `NOT IN (subquery)` ने 0 पंक्तियाँ क्यों दीं?

[EN] If the subquery returned even a single NULL value, every comparison becomes `x <> NULL` -> UNKNOWN, collapsing the entire NOT IN result to empty. Add `WHERE col IS NOT NULL` inside the subquery or switch to `NOT EXISTS`.

[HI] यदि सबक्वेरी ने एक भी NULL मान लौटाया, तो पूरी तुलना UNKNOWN हो जाती है और कोई भी पंक्ति नहीं बचती। सबक्वेरी में `IS NOT NULL` लगाएं या `NOT EXISTS` उपयोग करें।

Q3: Does BETWEEN work on text strings as well as numbers?

क्या BETWEEN केवल संख्याओं पर चलता है या टेक्स्ट (Strings) पर भी काम करता है?

[EN] Yes! `WHERE Name BETWEEN 'A' AND 'M'` works using alphabetical collation order, though `'M'` matches exact `'M'` and excludes `'Mahesh'` because `'Mahesh' > 'M'`.

[HI] हाँ! यह टेक्स्ट पर भी कॉलेशन के वर्णक्रमानुसार चलता है—बस ध्यान रखें `'M'` से बड़े नाम जैसे `'Mahesh'` इसमें शामिल नहीं होंगे।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)