Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) Notes in Hindi & English : रिलेशनल जॉइन्स: थीटा जॉइन, इक्वि-जॉइन और नेचुरल जॉइन (⨝) और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) (रिलेशनल जॉइन्स: थीटा जॉइन, इक्वि-जॉइन और नेचुरल जॉइन (⨝)) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Relational Joins—Theta Join (⋈_θ), Equi-Join, and Natural Join (⋈)—combine related tuples across two tables using arbitrary comparisons, equality predicates, or automatic common-attribute matching.

अध्याय सार: रिलेशनल जॉइन्स—थीटा जॉइन (⋈_θ), इक्वि-जॉइन और नेचुरल जॉइन (⋈)—दो अलग टेबल्स की संबंधित पंक्तियों को किसी शर्त, समानता या साझा कॉलम के आधार पर आपस में जोड़ते हैं।

Relational Joins: Theta Join, Equi-Join and Natural Join (⨝): Detailed Notes & Architecture (रिलेशनल जॉइन्स: थीटा जॉइन, इक्वि-जॉइन और नेचुरल जॉइन (⨝))

1. Theta Join (⋈_θ): General Conditional Join (थीटा जॉइन (Theta Join): सामान्य सशर्त जॉइन)

[EN] Theta Join generalizes joining two relations R and S under any arbitrary comparison predicate θ (using <, <=, >, >=, =, !=): R ⋈_θ S = σ_θ(R × S). For example, matching Student scores against GradeBand boundaries (Score >= MinMarks ∧ Score <= MaxMarks) uses a non-equality Theta Join.

[HI] Theta Join (R ⋈_θ S) दो टेबल्स को किसी भी तुलनात्मक शर्त (<, >, <=, >=, =, !=) पर जोड़ता है; गणितीय रूप से यह σ_θ(R × S) है। जैसे छात्र के अंकों को ग्रेड की न्यूनतम-अधिकतम सीमा टेबल से मिलाना।

2. Equi-Join: Equality-Only Matching (इक्वि-जॉइन (Equi-Join): केवल समानता आधारित जॉइन)

[EN] An Equi-Join is a special subset of Theta Join where the join predicate strictly uses equality (=) comparisons, e.g., Student ⋈_{Student.DeptID = Dept.ID} Dept. Crucially, Equi-Join retains BOTH matching equality columns side-by-side in the output table (both Student.DeptID and Dept.ID appear).

[HI] Equi-Join थीटा जॉइन का वह विशेष रूप है जिसमें शर्त केवल '=' (समानता) पर आधारित होती है (जैसे R.id = S.id)। ध्यान रहे: Equi-Join के आउटपुट में दोनों टेबल्स का साझा कॉलम दो बार अलग-अलग नाम से मौजूद रहता है।

3. Natural Join (R ⋈ S): Automatic Equality + Deduplicated Column (नेचुरल जॉइन (Natural Join): स्वतः मिलान व डुप्लीकेट कॉलम हटाना)

[EN] Natural Join (⋈) requires NO explicit condition: it automatically equates ALL attributes sharing identical names (and compatible types) across R and S, AND merges each shared attribute pair into ONE single column in the output schema! Mathematically, if R and S share attribute C: R ⋈ S = π_unique_attrs(σ_{R.C = S.C}(R × S)).

[HI] Natural Join (⋈) दोनों टेबल्स में समान नाम वाले सभी कॉलम्स पर स्वतः '=' शर्त लगाता है और आउटपुट में उस साझा कॉलम की केवल एक ही कॉपी रखता है। अतः डिग्री = deg(R) + deg(S) - साझा कॉलम्स।

4. Self-Join & Edge Cases of Natural Join (सेल्फ-जॉइन एवं नेचुरल जॉइन की सावधानियां)

[EN] When matching employees to their managers inside the SAME Employee table, a Self-Join aliases the table twice (Emp E JOIN Emp M ON E.MgrID = M.EmpID). In Natural Join, watch out for accidental column matches (like 'UpdatedDate' existing in both tables causing unexpected empty results!) and remember if zero columns match, Natural Join turns into Cartesian Product.

[HI] एक ही टेबल के अंदर संबंध (जैसे कर्मचारी और उसका मैनेजर) निकालने हेतु Self-Join उपयोग होता है। Natural Join में अनचाहे समान नाम वाले कॉलम्स (जैसे 'Date') से गलत मिलान का जोखिम रहता है।

Syntax, Formula & Technical Example (Relational Joins: Theta Join, Equi-Join and Natural Join (⨝))

-- Theta Join: R ⋈_{R.price < S.budget} S
-- Equi-Join:  Emp ⋈_{Emp.did = Dept.did} Dept (retains both did columns)
-- Natural Join: Emp ⋈ Dept (merges shared 'did' into 1 column)

SELECT E.Name, D.DeptName
FROM Emp E INNER JOIN Dept D ON E.DeptID = D.DeptID;

Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) Quick Reference & Comparison Table

Join TypeMatching ConditionDuplicate Join Column Retained?
Theta Join (⋈_θ)Any predicate (<, <=, >, >=, !=, =)Yes, keeps all columns from both tables
Equi-JoinEquality (=) condition onlyYes, retains both R.col and S.col
Natural Join (⋈)Auto-equality on ALL identically named columnsNo — merges shared columns into single copy
Self-JoinTable joined to itself using aliases (ρ)Uses explicit alias prefixes (E1.col, E2.col)

Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) Top 20 Bilingual MCQs with Answers

Q1. What is the crucial schema difference between an Equi-Join and a Natural Join on two tables sharing one column 'DeptID'?

(एक साझा कॉलम 'DeptID' वाली दो टेबल्स पर Equi-Join और Natural Join के परिणाम की डिग्री (कॉलम संख्या) में क्या अंतर होता है?)

(A) Equi-Join retains BOTH R.DeptID and S.DeptID columns, whereas Natural Join merges them into ONE DeptID column

(B) Natural Join supports '<' while Equi-Join uses '='

(C) Equi-Join drops all non-key columns automatically

(D) Natural Join keeps both columns while Equi-Join drops one

Correct Answer: (A)

[EN] If deg(R)=4 and deg(S)=3 sharing 1 column, Equi-Join produces degree 7 while Natural Join produces degree 6.

[HI] Equi-Join में साझा कॉलम दो बार (R.DeptID व S.DeptID) आता है, जबकि Natural Join उसे मिलाकर एक ही कॉलम रखता है।

Q2. Table R(A, B, C) and S(B, C, D) are joined using Natural Join (R ⋈ S). What is the degree (number of columns) of the result?

(टेबल R(A, B, C) और S(B, C, D) का Natural Join (R ⋈ S) करने पर आउटपुट की डिग्री (कॉलम संख्या) कितनी होगी?)

(A) 5

(B) 4 (A, B, C, D)

(C) 2

(D) 6

Correct Answer: (B)

[EN] Degree of R ⋈ S = deg(R) + deg(S) - |common attributes| = 3 + 3 - 2 = 4.

[HI] R में 3 व S में 3 कॉलम हैं जिनमें 2 (B, C) साझा हैं, अतः डिग्री = 3 + 3 - 2 = 4।

Q3. Which Join type permits non-equality operators like salary > grade_min_sal AND salary <= grade_max_sal?

(किस जॉइन में '>', '<' या '<=' जैसी असमानता शर्तों का उपयोग किया जा सकता है?)

(A) Cross Join

(B) Natural Join

(C) Theta Join

(D) Equi-Join

Correct Answer: (C)

[EN] Equi-Join and Natural Join use strict equality (=), whereas Theta Join supports all relational comparisons.

[HI] असमानता शर्तों (<, >, >=) के लिए केवल Theta Join प्रयोग होता है; Equi व Natural Join सिर्फ '=' पर चलते हैं।

Q4. If table R has columns (EmpID, Name) and S has columns (CourseID, Title) with NO overlapping names, what does R ⋈ S (Natural Join) produce?

(यदि R(EmpID, Name) और S(CourseID, Title) में एक भी कॉलम नाम समान न हो, तो R ⋈ S क्या परिणाम देगा?)

(A) Empty relation (0 rows)

(B) Cartesian Product (R × S) with |R| × |S| tuples

(C) Only R's rows padded with NULLs

(D) Syntax error

Correct Answer: (B)

[EN] With zero common attributes to match on, Natural Join trivially accepts every pair, acting identically to ×.

[HI] एक भी कॉमन कॉलम न होने पर Natural Join बिना किसी शर्त के दोनों टेबल्स का Cartesian Product (×) बन जाता है।

Q5. If primary key column A in R(A,B) joins via Natural Join with foreign key A (with NULLs allowed) in S(A,C), what is the MAXIMUM cardinality when |R|=10, |S|=50 (A is PK in R)?

(यदि R(A,B) में A प्राइमरी की (10 रो) है और S(A,C) में A फॉरेन की (50 रो) है, तो R ⋈ S में अधिकतम कितनी रो आ सकती हैं?)

(A) 50 tuples (each row in S matches at most 1 unique PK row in R)

(B) 60 tuples

(C) 500 tuples

(D) 10 tuples

Correct Answer: (A)

[EN] Since A is Primary Key in R, each S tuple matches at most ONE R tuple, capping total join output at |S| = 50.

[HI] R में A अद्वितीय (PK) होने से S की प्रत्येक 50 में से हर पंक्ति R की अधिकतम 1 ही पंक्ति से जुड़ सकती है, अतः अधिकतम 50 रो।

Q6. What does R ⋈_c S evaluate to mathematically using fundamental operators?

(मूलभूत ऑपरेटर्स का उपयोग करके Theta Join (R ⋈_c S) को गणितीय रूप से कैसे परिभाषित किया जाता है?)

(A) π_c(R ∪ S)

(B) R - (R - S)

(C) σ_c(R × S)

(D) σ_c(R ∩ S)

Correct Answer: (C)

[EN] Theta Join is explicitly defined as applying Selection σ_c onto Cartesian Product R × S.

[HI] Theta Join की आधिकारिक परिभाषा σ_c(R × S) होती है।

Q7. How do you find 'Employees who earn more than their own Manager' from a single Employee(EmpID, Name, Salary, MgrID) table?

(एक ही Employee(EmpID, Name, Salary, MgrID) टेबल से 'मैनेजर से अधिक कमाने वाले कर्मचारी' निकालने के लिए कौन सा जॉइन चाहिए?)

(A) Natural Join

(B) Set Union

(C) Cross Join only

(D) Self-Join (joining Employee E with Employee M on E.MgrID = M.EmpID AND E.Salary > M.Salary)

Correct Answer: (D)

[EN] Relating rows within the same table requires Self-Joining two aliased instances of that table.

[HI] एक ही टेबल की दो पंक्तियों की आपसी तुलना (कर्मचारी व उसका मैनेजर) के लिए Self-Join उपयोग होता है।

Q8. Which Join operator does NOT allow an ON or USING clause in standard SQL?

(मानक SQL में किस जॉइन के साथ ON या USING क्लॉज लिखने की अनुमति नहीं होती?)

(A) INNER JOIN

(B) NATURAL JOIN

(C) SELF JOIN

(D) LEFT OUTER JOIN

Correct Answer: (B)

[EN] NATURAL JOIN derives its matching condition strictly from identical column names; adding ON causes an SQL syntax error.

[HI] NATURAL JOIN स्वतः समान नाम वाले कॉलम चुनता है, अतः इसके साथ ON या USING लिखने पर सिंटैक्स एरर आती है।

Q9. Is Natural Join associative: is (R ⋈ S) ⋈ T identical to R ⋈ (S ⋈ T)?

(क्या रिलेशनल अलजेब्रा में Natural Join साहचर्य (Associative) गुण का पालन करता है?)

(A) Only in MySQL

(B) No, Natural Join is never associative

(C) Yes — both commutative and associative (up to column order)

(D) Only if all tables share zero columns

Correct Answer: (C)

[EN] Natural Join is both commutative and associative, allowing query optimizers to reorder multi-table joins for speed.

[HI] हाँ — Natural Join क्रमविनिमेय और साहचर्य दोनों होता है जिससे ऑप्टिमाइज़र तेज क्रम चुन सकते हैं।

Q10. What does SQL's JOIN ... USING (DeptID) syntax imitate?

(SQL में JOIN ... USING (DeptID) सिंटैक्स किस व्यवहार की नकल करता है?)

(A) An Equi-Join on specified column 'DeptID' that merges the duplicate DeptID column cleanly like Natural Join

(B) A Set Difference

(C) A Theta Join with '<'

(D) A Cross Join without filtering

Correct Answer: (A)

[EN] JOIN USING (col) prevents accidental matches on other shared columns like 'CreatedAt' while still merging the named join column.

[HI] JOIN USING(col) केवल बताए गए कॉलम पर जॉइन करता है और Natural Join की तरह उसे एक ही बार आउटपुट में रखता है।

Q11. Why is NATURAL JOIN often discouraged in production software engineering?

(प्रोडक्शन सॉफ्टवेयर में NATURAL JOIN का प्रयोग अक्सर क्यों हतोत्साहित किया जाता है?)

(A) SQL Server bans all joins

(B) It deletes primary keys automatically

(C) NATURAL JOIN runs 100x slower than Cross Join

(D) Adding an unrelated column like 'ModifiedAt' to both tables later silently breaks existing NATURAL JOIN queries

Correct Answer: (D)

[EN] Explicit ON R.col = S.col prevents silent schema changes from breaking query logic.

[HI] यदि भविष्य में दोनों टेबल्स में 'UpdatedAt' जैसा नया कॉलम जुड़ जाए, तो NATURAL JOIN चुपचाप उस पर भी मिलान कर क्वेरी खराब कर देगा।

Q12. If table R has tuple (1, NULL) and S has tuple (1, NULL) joined via R ⋈_R.B=S.B S, do the two NULL values match in SQL INNER JOIN?

(यदि R व S दोनों में कॉलम B का मान NULL हो, तो SQL INNER JOIN ON R.B = S.B में क्या दोनों NULL आपस में मैच होंगे?)

(A) Only in Natural Join

(B) Yes, NULL matches NULL

(C) No — NULL = NULL evaluates to UNKNOWN, so NULL rows are excluded from Inner Join results

(D) Throws NullPointerError

Correct Answer: (C)

[EN] Standard equality joins never match NULL to NULL unless specialized null-safe operators (like MySQL <=> or IS NOT DISTINCT FROM) are used.

[HI] SQL में NULL = NULL सत्य नहीं होता (UNKNOWN देता है), इसलिए साधारण Inner Join NULL वाली पंक्तियाँ छोड़ देता है।

Q13. What is a Semi-Join (R ⋉ S) in Relational Algebra?

(रिलेशनल अलजेब्रा में Semi-Join (R ⋉ S) का क्या कार्य है?)

(A) Joins only the first half of R

(B) Doubles duplicate columns

(C) Includes unmatched NULL rows from S

(D) Returns only those tuples of left relation R that match at least one tuple in S (retaining only R's attributes)

Correct Answer: (D)

[EN] R ⋉ S = π_attrs(R)(R ⋈ S); heavily used in distributed databases to reduce network transmission.

[HI] Semi-Join में केवल R के वे कॉलम व पंक्तियाँ आती हैं जिनका S में मैच मिल जाए (SQL में EXISTS जैसा)।

Q14. Given R(A,B) with 3 rows {(1,10), (2,20), (3,30)} and S(B,C) with 3 rows {(10,5), (10,6), (40,7)}, how many rows are in R ⋈ S?

(R={(1,10),(2,20),(3,30)} और S={(10,5),(10,6),(40,7)} का Natural Join (R ⋈ S) कितनी पंक्तियाँ देगा?)

(A) 2 rows: (1,10,5) and (1,10,6)

(B) 1 row

(C) 9 rows

(D) 3 rows

Correct Answer: (A)

[EN] Only B=10 matches between R and S, pairing with two tuples in S to emit 2 rows; 20, 30, and 40 find no match.

[HI] केवल B=10 दोनों में मैच होता है जो S की दो पंक्तियों से जुड़कर कुल 2 पंक्तियाँ देता है।

Q15. Which Join returns ONLY rows that satisfy the join condition in both tables (excluding unmatched rows)?

(कौन सा जॉइन केवल उन्हीं पंक्तियों को लौटाता है जिनका दोनों टेबल्स में मैच मिलता है (बिना मैच वाली पंक्तियाँ छोड़कर)?)

(A) Inner Join (Equi-Join / Natural Join / Theta Join)

(B) Left Outer Join

(C) Cross Join

(D) Full Outer Join

Correct Answer: (A)

[EN] Inner joins discard non-matching tuples, whereas Outer joins preserve non-matching tuples padded with NULLs.

[HI] Inner Join (Equi, Natural, Theta) केवल मैचिंग पंक्तियाँ रखता है; बिना मैच वाली पंक्तियों हेतु Outer Join चाहिए।

Q16. What is the MINIMUM cardinality of an Equi-Join R ⋈_{R.k = S.k} S when |R|=100 and |S|=100?

(यदि |R|=100 और |S|=100 हों, तो Equi-Join में न्यूनतम कितनी पंक्तियाँ आ सकती हैं?)

(A) 1

(B) 200

(C) 100

(D) 0 (when no matching key value exists between R and S)

Correct Answer: (D)

[EN] If sets of join key values in R and S are completely disjoint, Inner Join returns 0 rows.

[HI] यदि दोनों टेबल्स के की-मान बिल्कुल न मिलें, तो Inner/Equi-Join में न्यूनतम 0 पंक्तियाँ मिलेंगी।

Q17. Within Relational Joins: Theta Join, Equi-Join and Natural Join (⨝), which join type directly maps to: "Any predicate (<, <=, >, >=, !=, =)"?

(Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) में कौन सा Join Type सीधे "Any predicate (<, <=, >, >=, !=, =)" से संबंधित है?)

(A) Equi-Join

(B) Theta Join (⋈_θ)

(C) Self-Join

(D) Natural Join (⋈)

Correct Answer: (B)

[EN] In Relational Joins: Theta Join, Equi-Join and Natural Join (⨝), 'Theta Join (⋈_θ)' handles 'Any predicate (<, <=, >, >=, !=, =)' (Yes, keeps all columns from both tables).

[HI] Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) में 'Theta Join (⋈_θ)' का कार्य/विवरण 'Any predicate (<, <=, >, >=, !=, =)' (Yes, keeps all columns from both tables) है।

Q18. Which option accurately describes 'Equi-Join' in Relational Joins: Theta Join, Equi-Join and Natural Join (⨝)?

(Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) के संदर्भ में 'Equi-Join' की सही विशेषता कौन सी है?)

(A) Any predicate (<, <=, >, >=, !=, =)

(B) Equality (=) condition only

(C) Auto-equality on ALL identically named columns

(D) Table joined to itself using aliases (ρ)

Correct Answer: (B)

[EN] 'Equi-Join' provides 'Equality (=) condition only' — key point: Yes, retains both R.col and S.col.

[HI] 'Equi-Join' का मुख्य विवरण 'Equality (=) condition only' है (Yes, retains both R.col and S.col)।

Q19. In Relational Joins: Theta Join, Equi-Join and Natural Join (⨝), identify the correct parameter for the specification: "Auto-equality on ALL identically named columns".

(Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) में "Auto-equality on ALL identically named columns" विवरण किस विकल्प के लिए सही है?)

(A) Self-Join

(B) Equi-Join

(C) Natural Join (⋈)

(D) Theta Join (⋈_θ)

Correct Answer: (C)

[EN] 'Natural Join (⋈)' corresponds to 'Auto-equality on ALL identically named columns' (No — merges shared columns into single copy).

[HI] 'Natural Join (⋈)' का संबंध 'Auto-equality on ALL identically named columns' (No — merges shared columns into single copy) से है।

Q20. Considering Relational Joins: Theta Join, Equi-Join and Natural Join (⨝), what key behavior defines 'Self-Join'?

(Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) में 'Self-Join' की मुख्य भूमिका या मान क्या है?)

(A) Equality (=) condition only

(B) Any predicate (<, <=, >, >=, !=, =)

(C) Auto-equality on ALL identically named columns

(D) Table joined to itself using aliases (ρ)

Correct Answer: (D)

[EN] 'Self-Join' represents 'Table joined to itself using aliases (ρ)' (Uses explicit alias prefixes (E1.col, E2.col)).

[HI] 'Self-Join' का अर्थ/मान 'Table joined to itself using aliases (ρ)' है (Uses explicit alias prefixes (E1.col, E2.col))।

Relational Joins: Theta Join, Equi-Join and Natural Join (⨝) — Exam FAQs

Q1: Is INNER JOIN the same as JOIN in SQL?

क्या SQL में केवल JOIN लिखना और INNER JOIN लिखना एक ही बात है?

[EN] Yes! In ANSI SQL, writing JOIN without a modifier defaults directly to INNER JOIN.

[HI] हाँ! SQL में सिर्फ JOIN लिखने का अर्थ डिफ़ॉल्ट रूप से INNER JOIN ही होता है।

Q2: Which is faster: Equi-Join using ON or comma-separated WHERE join?

ON वाला JOIN तेज होता है या WHERE वाला पुराना सिंटैक्स?

[EN] Modern database query optimizers generate identical execution plans for both, but explicit INNER JOIN ... ON is cleaner, prevents accidental Cross Joins, and is mandatory for Outer Joins.

[HI] ऑप्टिमाइज़र दोनों को समान गति से चलाता है, पर JOIN ... ON लिखना साफ रहता है और अनजाने Cross Join की गलती से बचाता है।

Q3: What is the difference between Semi-Join and Anti-Join?

Semi-Join (⋉) और Anti-Join में क्या अंतर है?

[EN] Semi-Join returns rows of R that DO have a match in S (SQL IN/EXISTS), while Anti-Join returns rows of R that have NO match in S (SQL NOT EXISTS).

[HI] Semi-Join R की वे पंक्तियाँ देता है जिनका S में मैच मिले, और Anti-Join वे देता है जिनका S में कोई मैच न मिले।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)