🚂 RailGuruji
Databases and SQLडेटाबेस और एसक्यूएल5 / 7

Joins, sub-queries and indexesजॉइन, सब-क्वेरी और इंडेक्स

Practise the chapter · 13 Qपूरे अध्याय का अभ्यास · 13 प्रश्न
Updated अद्यतन 07 Oct 2026
This chapterयह अध्याय asked in 1 exam1 परीक्षा में पूछा गया
1
THE JOINSजॉइन
A JOIN combines rows from two tables on a matching column.
  • INNER JOIN: only the rows with matching values in BOTH tables. JOIN alone means INNER JOIN
  • LEFT OUTER JOIN: every row of the LEFT table, with NULL where the right has no match
  • RIGHT OUTER JOIN: every row of the RIGHT table, with NULL where the left has no match
  • FULL OUTER JOIN: every row of both tables
  • SELF JOIN: a table joined to itself
  • CROSS JOIN: every row paired with every row, the CARTESIAN PRODUCT
So you use an outer join when you must keep the rows that have no match.
जॉइन दो तालिकाओं की पंक्तियों को मेल खाते कॉलम पर जोड़ता है।
  • इनर जॉइन: केवल वे पंक्तियाँ जिनके मान दोनों तालिकाओं में मेल खाते हैं। अकेले जॉइन का अर्थ इनर जॉइन है
  • लेफ्ट आउटर जॉइन: बाईं तालिका की हर पंक्ति, जहाँ दाईं में मेल न हो वहाँ NULL
  • राइट आउटर जॉइन: दाईं तालिका की हर पंक्ति, जहाँ बाईं में मेल न हो वहाँ NULL
  • फुल आउटर जॉइन: दोनों तालिकाओं की हर पंक्ति
  • सेल्फ जॉइन: तालिका का स्वयं से जॉइन
  • क्रॉस जॉइन: हर पंक्ति हर पंक्ति के साथ, अर्थात् कार्टेशियन गुणनफल
अर्थात् जब आपको बिना मेल वाली पंक्तियाँ भी रखनी हों, तब आप आउटर जॉइन लेते हैं।
2
NESTED QUERIESनेस्टेड क्वेरी
In a NESTED QUERY, the result of one query, the SUB-QUERY, is used by another query.
  • EXISTS is true if the sub-query returns at least one row, and false if it returns none
  • ANY and SOME are true if the value matches at least one value the sub-query returns
  • ALL is true only if the value satisfies the condition for every value returned
  • A CORRELATED sub-query refers to the outer query, so it runs once for each outer row
You can write: SELECT ename FROM emp WHERE sal > (SELECT AVG(sal) FROM emp). So ANY means at least one, and ALL means every one.
नेस्टेड क्वेरी में एक क्वेरी, अर्थात् सब-क्वेरी, का परिणाम दूसरी क्वेरी उपयोग करती है।
  • EXISTS सत्य है यदि सब-क्वेरी कम से कम एक पंक्ति लौटाए, और असत्य यदि कोई न लौटाए
  • ANY और SOME सत्य हैं यदि मान सब-क्वेरी के लौटाए किसी एक मान से भी मेल खाए
  • ALL तभी सत्य है जब मान लौटाए गए हर मान के लिए शर्त पूरी करे
  • कोरिलेटेड सब-क्वेरी बाहरी क्वेरी का संदर्भ लेती है, इसलिए हर बाहरी पंक्ति के लिए एक बार चलती है
आप लिख सकते हैं: SELECT ename FROM emp WHERE sal > (SELECT AVG(sal) FROM emp)। अर्थात् ANY का अर्थ कम से कम एक है, और ALL का अर्थ हर एक।
3
GROUP BY AND HAVINGGROUP BY और HAVING
  • GROUP BY collects rows with the same value into groups, so a group function works on each group
  • HAVING filters the GROUPS, just as WHERE filters the rows
  • WHERE runs before grouping; HAVING runs after it
  • SELECT deptno, AVG(sal) FROM emp GROUP BY deptno HAVING COUNT(*) > 5 gives the average pay of departments with more than five people
  • ROWNUM in Oracle limits the rows returned, as in WHERE ROWNUM <= 5
So you filter rows with WHERE, and groups with HAVING.
  • GROUP BY समान मान वाली पंक्तियों को समूहों में रखता है, ताकि ग्रुप फंक्शन हर समूह पर चले
  • HAVING समूहों को छानता है, जैसे WHERE पंक्तियों को छानता है
  • WHERE समूह बनाने से पहले चलता है; HAVING उसके बाद
  • SELECT deptno, AVG(sal) FROM emp GROUP BY deptno HAVING COUNT(*) > 5 पाँच से अधिक लोगों वाले विभागों का औसत वेतन देता है
  • ओरेकल में ROWNUM लौटाई गई पंक्तियाँ सीमित करता है, जैसे WHERE ROWNUM <= 5
अर्थात् आप पंक्तियाँ WHERE से, और समूह HAVING से छानते हैं।
4
INDEXES AND QUERY PARSINGइंडेक्स और क्वेरी पार्सिंग
  • An INDEX maps a column's values to their ROWIDs. A rowid gives the file, the block and the row
  • An index is a tree: smaller values go left of their parent. This is the B-TREE index
  • Index the columns your queries use often. Do NOT index columns with few unique values, or small tables
  • When a query is PARSED, the syntax is checked, and the objects are checked to exist
  • The parser then checks your access rights, and finds the OPTIMAL PATH, the execution plan
So an index shortens the search path to your data.
  • इंडेक्स कॉलम के मानों को उनके रोआईडी से जोड़ता है। रोआईडी फाइल, ब्लॉक और पंक्ति बताता है
  • इंडेक्स एक वृक्ष है: छोटे मान अपने पैरेंट के बाएँ जाते हैं। यह बी-ट्री इंडेक्स है
  • उन कॉलमों पर इंडेक्स बनाएँ जिन्हें आपकी क्वेरी अक्सर उपयोग करती हैं। कम अद्वितीय मानों वाले कॉलमों, या छोटी तालिकाओं पर इंडेक्स न बनाएँ
  • क्वेरी पार्स होने पर सिंटैक्स जाँचा जाता है, और ऑब्जेक्टों का अस्तित्व जाँचा जाता है
  • फिर पार्सर आपके पहुँच अधिकार जाँचता है, और सर्वोत्तम मार्ग, अर्थात् निष्पादन योजना, खोजता है
अर्थात् इंडेक्स आपके डेटा तक खोज का मार्ग छोटा करता है।
Report an error on this pageइस पेज में गलती बताएँ

Finished this page? Practise its chapter.यह पेज पूरा हुआ? अब इसके अध्याय का अभ्यास कीजिए।

Only questions asked in real past papersकेवल पिछले वर्षों के प्रश्नपत्रों में पूछे गए प्रश्नOnly practice questions, none from a past paperकेवल अभ्यास प्रश्न, कोई भी पिछले प्रश्नपत्र से नहींPast-paper and practice questions togetherपिछले प्रश्नपत्रों के और अभ्यास प्रश्न, दोनों

or take the free Mock CBTया फ्री Mock CBT दें