पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 15 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
SQL को घोषणात्मक (declarative) भाषा कहा जाता है। इसका सीधा अर्थ क्या है?
SQL is called a declarative language. What does this directly mean?
Aक्वेरी में बताया जाता है कि कौन-सा परिणाम चाहिए, और उसे पाने का रास्ता DBMS ख़ुद तय करता हैThe query states which result is wanted, and the DBMS itself settles the route to obtain it
Bक्वेरी में हर चरण क्रमवार बताना पड़ता है कि आँकड़े कैसे पढ़े जाएँThe query must state step by step how the data is to be read
Cक्वेरी चलाने से पहले उसे किसी procedural भाषा में बदलना पड़ता हैThe query must be rewritten in some procedural language before it can run
Dक्वेरी में हर बार table का भौतिक क्रम बताना पड़ता हैThe query must state the physical ordering of the table every time
सही उत्तर / Answer: (A)
हल / Solution
घोषणात्मक का अर्थ है — «क्या चाहिए» लिखना, «कैसे लाना है» नहीं। एक ही परिणाम के लिए index से पढ़ा जाए या पूरी table छानी जाए, और join किस ढंग से हो, यह DBMS का भाग ख़ुद चुन लेता है। इसी कारण एक ही परिणाम देने वाली कई भिन्न क्वेरी लिखी जा सकती हैं। चरण-दर-चरण बताना procedural भाषा का लक्षण है, और SQL को चलाने के लिए उसे हाथ से किसी दूसरी भाषा में बदलना नहीं पड़ता।
Declarative means stating what is wanted and not how to fetch it. Whether the rows are read through an index or by scanning the whole table, and in what manner the join is carried out, is chosen by the DBMS itself. This is why several different queries can be written for one and the same result. Spelling out every step is the mark of a procedural language, and SQL needs no hand translation to run.
प्रश्न 2उत्तर + हल
दो क्वेरी A और B के परिणामों पर set संक्रिया लगाई जाए, तो किस संक्रिया में A और B की जगह बदल देने से पंक्तियों का समुच्चय भी बदल जाता है?
When a set operation is applied to the results of two queries A and B, in which operation does swapping A and B also change the set of rows obtained?
AUNION
BINTERSECT
CUNION ALL
DMINUS
सही उत्तर / Answer: (D)
हल / Solution
MINUS पहली क्वेरी की वे पंक्तियाँ देता है जो दूसरी में नहीं हैं, इसलिए वह दिशा पर निर्भर है — A में पड़ी अतिरिक्त पंक्तियाँ और B में पड़ी अतिरिक्त पंक्तियाँ दो अलग चीज़ें हैं, सो जगह बदलते ही समुच्चय बदल जाता है। UNION तथा UNION ALL दोनों तरफ़ की पंक्तियाँ मिला देते हैं, और INTERSECT केवल साझा पंक्तियाँ देता है; इन तीनों में क्रम बदलने से समुच्चय वही रहता है।
MINUS returns those rows of the first query that are absent from the second, so it depends on direction: the rows left over in A and the rows left over in B are two different things, and swapping the two changes the set at once. UNION and UNION ALL merge the rows of both sides, while INTERSECT returns only the shared rows, so for all three the set stays the same when the order is reversed.
प्रश्न 3उत्तर + हल
चार table को एक ही क्वेरी में inner join करना है। बेमतलब का Cartesian गुणनफल न बने, इसके लिए कम से कम कितनी join शर्तें चाहिए?
Four tables are to be inner joined in a single query. At least how many join conditions are needed so that no meaningless Cartesian product is formed?
AदोTwo
BतीनThree
CचारFour
DआठEight
सही उत्तर / Answer: (B)
हल / Solution
हर join शर्त दो table को आपस में बाँधती है, इसलिए n table को एक ही जाल में जोड़ने के लिए कम से कम n घटा एक शर्तें चाहिए। चार table के लिए यह संख्या तीन निकलती है। एक भी शर्त कम पड़ी तो कोई table बिना बँधा रह जाता है, और उसकी हर पंक्ति बाक़ी हर पंक्ति से जुड़कर परिणाम कई गुना फुला देती है। चार या आठ शर्तें लिखना मना नहीं, पर न्यूनतम तीन ही है।
Each join condition ties two tables together, so at least one fewer condition than the number of tables is needed to link them all into a single web. For four tables that number works out to three. If even one condition is missing, some table stays unlinked and each of its rows pairs with every other row, swelling the result many times over. Writing four or eight conditions is allowed, but the minimum is three.
प्रश्न 4उत्तर + हल
SELECT में बनाया गया स्तंभ का alias उसी क्वेरी के WHERE में नहीं चलता, पर ORDER BY में चल जाता है। इसका कारण क्या है?
A column alias created in SELECT cannot be used in the WHERE clause of the same query, yet it can be used in ORDER BY. What is the reason?
AORDER BY अपने लिए नया alias ख़ुद बना लेता हैORDER BY creates a fresh alias of its own
BWHERE में किसी भी तरह का alias इस्तेमाल करने की मनाही हैUsing an alias of any kind in WHERE is forbidden
CWHERE, SELECT से पहले चलता है और ORDER BY उसके बाद, इसलिए WHERE के समय alias बना ही नहीं होताWHERE runs before SELECT and ORDER BY runs after it, so the alias does not yet exist when WHERE runs
Dalias केवल संख्यात्मक स्तंभों पर ही चलता हैAn alias works only on numeric columns
सही उत्तर / Answer: (C)
हल / Solution
चलने का क्रम तय करता है कि कौन-सा नाम कहाँ मौजूद है। WHERE का काम SELECT से पहले निपट जाता है, इसलिए उस समय select list के नए नाम बने ही नहीं होते और alias अपरिचित रहता है — वहाँ पूरा व्यंजक दोहराना पड़ता है। ORDER BY सबसे अंत में, SELECT के बाद चलता है, तब तक नाम तैयार हो चुका होता है, सो वहाँ alias सीधे चल जाता है। table का alias तो WHERE में भी चलता है।
The order of execution decides which name exists where. The work of WHERE is finished before SELECT, so at that moment the new names of the select list have not been created and the alias is unknown there; the whole expression has to be repeated instead. ORDER BY runs last of all, after SELECT, by which time the name is ready, so an alias works there. A table alias, by contrast, does work in WHERE.
प्रश्न 5उत्तर + हल
SQL क्वेरी चलते समय नीचे दिए clause पर काम होने का सही क्रम कौन-सा है?
When an SQL query runs, which of the following is the correct order in which the clauses are processed?
ASELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY
BFROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
CFROM → SELECT → WHERE → GROUP BY → HAVING → ORDER BY
DFROM → WHERE → SELECT → GROUP BY → HAVING → ORDER BY
सही उत्तर / Answer: (B)
हल / Solution
लिखने का क्रम और चलने का क्रम एक नहीं हैं। लिखते समय SELECT सबसे आगे आता है, पर चलते समय पहले FROM से आँकड़ों का स्रोत बनता है, फिर WHERE पंक्तियाँ छाँटता है, फिर GROUP BY उनके समूह बनाता है, फिर HAVING समूहों पर शर्त लगाता है, इसके बाद SELECT स्तंभ चुनता है, और सबसे अंत में ORDER BY परिणाम को क्रम में लगाता है। SELECT से शुरू होने वाला विकल्प लिखने का क्रम बताता है, चलने का नहीं।
The order of writing and the order of execution are not the same. SELECT comes first in writing, but in execution FROM first builds the source of the data, WHERE then filters the rows, GROUP BY forms them into groups, HAVING puts a condition on those groups, after which SELECT picks out the columns, and ORDER BY arranges the result at the very end. The option beginning with SELECT gives the writing order, not the execution order.
प्रश्न 6उत्तर + हल
आँकड़ों को सँभालने के ढंग में SQL तथा C या Java जैसी procedural भाषा के बीच मूल अंतर क्या है?
In the way data is handled, what is the basic difference between SQL and a procedural language such as C or Java?
ASQL एक ही कथन से पंक्तियों के पूरे समुच्चय पर काम करती है, procedural भाषा में loop चलाकर एक-एक record परSQL works on a whole set of rows in one statement, while a procedural language works record by record through a loop
BSQL एक-एक record पर काम करती है, और procedural भाषा पूरे समुच्चय परSQL works record by record, while a procedural language works on the whole set
Cदोनों एक-एक record पर ही काम करती हैंBoth of them work record by record only
DSQL में आँकड़े बदले नहीं जा सकते, केवल पढ़े जा सकते हैंData cannot be changed in SQL, it can only be read
सही उत्तर / Answer: (A)
हल / Solution
SQL घोषणात्मक भाषा है — एक UPDATE या SELECT कथन लाखों पंक्तियों पर एक साथ लागू हो जाता है, और «कैसे» करना है यह DBMS तय करता है। procedural भाषा में वही काम करने के लिए record एक-एक उठाकर loop चलाना पड़ता है और हर चरण क्रमवार लिखना पड़ता है। SQL में INSERT, UPDATE तथा DELETE से आँकड़े बदले भी जाते हैं, इसलिए केवल पढ़ने वाली बात सरासर ग़लत है।
SQL is a declarative language: one UPDATE or SELECT statement applies to millions of rows at once, and the DBMS itself settles how the work is to be done. To do the same job in a procedural language, records must be picked up one at a time in a loop and every step written out in sequence. SQL also changes data through INSERT, UPDATE and DELETE, so the read-only claim is plainly wrong.
प्रश्न 7उत्तर + हल
GROUP BY वाली क्वेरी की select list में किस तरह के स्तंभ या व्यंजक आ सकते हैं?
In the select list of a query that uses GROUP BY, what kind of columns or expressions may appear?
Aकेवल वे स्तंभ जो WHERE में इस्तेमाल हुए हैंOnly the columns that have been used in WHERE
Btable का कोई भी स्तंभ, इस पर कोई रोक नहींAny column of the table; there is no restriction on this
Cकेवल aggregate function, कोई साधारण स्तंभ नहींOnly aggregate functions, and no plain column
Dकेवल वे स्तंभ जो GROUP BY में दिए गए हैं, तथा aggregate functionOnly the columns named in GROUP BY, together with aggregate functions
सही उत्तर / Answer: (D)
हल / Solution
GROUP BY हर समूह को एक पंक्ति में समेट देता है, इसलिए select list में ऐसा ही मान आ सकता है जो पूरे समूह के लिए एक ही हो। समूह बनाने वाले स्तंभ का मान समूह भर में एक ही रहता है, और aggregate function पूरे समूह को एक मान में बदल देता है। कोई तीसरा स्तंभ लिखने पर DBMS तय नहीं कर पाता कि समूह की किस पंक्ति का मान दिखाए, सो वह त्रुटि देता है।
GROUP BY collapses every group into a single row, so the select list may hold only such a value as is the same for the whole group. A grouping column keeps one value throughout its group, and an aggregate function reduces the whole group to one value. If any third column is written, the DBMS cannot decide which row of the group to show its value from, so it reports an error.
प्रश्न 8उत्तर + हल
किसी क्वेरी में ORDER BY city, name लिखा गया है। पंक्तियाँ किस तरह क्रम में लगेंगी?
A query is written with ORDER BY city, name. How will the rows be arranged?
Aकेवल city के क्रम में, name की पूरी उपेक्षा करकेBy city only, ignoring name altogether
Bपहले name के क्रम में, और एक ही name वाली पंक्तियों में city के क्रम मेंFirst by name, and within rows of the same name by city
Ccity और name को जोड़कर बने एक ही पाठ के क्रम मेंBy the single text formed by joining city and name together
Dपहले city के क्रम में, और एक ही city वाली पंक्तियों में name के क्रम मेंFirst by city, and within rows of the same city by name
सही उत्तर / Answer: (D)
हल / Solution
ORDER BY में स्तंभ बाएँ से दाएँ प्राथमिकता के क्रम में लिखे जाते हैं। पहले city पर क्रम लगता है; जहाँ दो पंक्तियों की city एक ही निकले, वहीं बराबरी तोड़ने के लिए name देखा जाता है। इसलिए दूसरा स्तंभ उपेक्षित नहीं होता, पर उसका असर केवल बराबरी वाली पंक्तियों पर दिखता है। दोनों स्तंभों को जोड़कर एक पाठ बनाने जैसा कुछ नहीं होता, और प्राथमिकता उलटी भी नहीं पड़ती।
In ORDER BY the columns are written in order of priority from left to right. The rows are first arranged by city, and where two rows carry the same city, name is consulted to break that tie. The second column is therefore not ignored, but its effect shows only among the tied rows. The two columns are not joined into one text, and the priority is not reversed either.
प्रश्न 9उत्तर + हल
कोई subquery एक से अधिक पंक्तियाँ लौटा रही है। उसके परिणाम से तुलना करने के लिए बाहरी क्वेरी में बराबर के चिह्न की जगह क्या लिखना चाहिए?
A subquery returns more than one row. In the outer query, what should be written in place of the equality sign to compare with its result?
AIN
BLIKE
CBETWEEN
DIS NULL
सही उत्तर / Answer: (A)
हल / Solution
बराबर का चिह्न एक ही मान से तुलना करता है, इसलिए एक से अधिक पंक्तियाँ लौटाने वाली subquery के साथ लगाने पर क्वेरी त्रुटि दे देती है। कई मानों की सूची से तुलना का काम IN करता है, जो सूची के किसी एक मान के मिलने पर शर्त पूरी मान लेता है। LIKE पाठ के साँचे से मिलाता है, BETWEEN दो सिरों के बीच का परास देखता है, और IS NULL केवल मान के न होने की जाँच करता है।
The equality sign compares against a single value, so attaching it to a subquery that returns several rows makes the query fail with an error. Comparing against a list of values is the work of IN, which treats the condition as satisfied when any one value in the list matches. LIKE matches text against a pattern, BETWEEN tests a range between two end points, and IS NULL only checks for the absence of a value.
प्रश्न 10उत्तर + हल
किसी साधारण, अर्थात् non-correlated subquery वाली क्वेरी में चलने का क्रम क्या होता है?
In a query that contains a plain, that is a non-correlated, subquery, what is the order of execution?
Aभीतरी क्वेरी बाहरी क्वेरी की हर पंक्ति के लिए दोबारा चलती हैThe inner query runs again for every row of the outer query
Bबाहरी क्वेरी पहले पूरी चलती है, उसके बाद भीतरी क्वेरीThe outer query runs fully first, and the inner query runs after it
Cभीतरी क्वेरी पहले एक बार चलती है, और उसका परिणाम बाहरी क्वेरी इस्तेमाल करती हैThe inner query runs once first, and the outer query uses its result
Dदोनों साथ-साथ, एक-दूसरे से पूरी तरह स्वतंत्र चलती हैंBoth run side by side, wholly independent of each other
सही उत्तर / Answer: (C)
हल / Solution
non-correlated subquery बाहरी क्वेरी के किसी स्तंभ पर निर्भर नहीं होती, इसलिए वह अपने आप पूरी चल जाती है और उसका एक ही परिणाम बाहरी क्वेरी की शर्त में रख दिया जाता है। हर पंक्ति के लिए दोबारा चलना correlated subquery का लक्षण है, जहाँ भीतरी क्वेरी बाहरी पंक्ति का मान माँगती है। बाहरी क्वेरी पहले पूरी चल भी नहीं सकती, क्योंकि उसकी शर्त तब तक अधूरी रहती है।
A non-correlated subquery does not depend on any column of the outer query, so it runs through on its own and its single result is then placed into the condition of the outer query. Running afresh for every row is the mark of a correlated subquery, where the inner query asks for a value from the current outer row. The outer query cannot run fully first, because its condition stays incomplete until then.
आगे के 15 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
शर्त WHERE phone = NULL वाली क्वेरी एक भी पंक्ति नहीं लौटाती, जबकि table में phone ख़ाली वाली पंक्तियाँ मौजूद हैं। इसका कारण क्या है?
A query with the condition WHERE phone = NULL returns no row at all, even though the table does hold rows in which phone is empty. What is the reason?
ANULL से की गई तुलना का नतीजा सही या ग़लत नहीं, अज्ञात होता है, इसलिए कोई पंक्ति नहीं छनतीA comparison with NULL yields UNKNOWN rather than true or false, so no row passes the filter
BWHERE में बराबर का चिह्न चलता ही नहींThe equality sign is not allowed in WHERE at all
CNULL को पहले शून्य में बदलना पड़ता हैNULL has to be converted into zero first
Dphone जैसे पाठ स्तंभ WHERE में नहीं लिए जा सकतेText columns such as phone cannot be used in WHERE
SQL में COUNT या SUM जैसे aggregate function की शर्त WHERE clause में नहीं लिखी जा सकती। इसका कारण क्या है?
In SQL, a condition on an aggregate function such as COUNT or SUM cannot be written in the WHERE clause. What is the reason?
AWHERE में संख्यात्मक स्तंभ इस्तेमाल नहीं किए जा सकतेNumeric columns cannot be used in WHERE
BWHERE समूह बनने से पहले चलता है, इसलिए उस समय कोई aggregate मान मौजूद ही नहीं होताWHERE runs before grouping, so no aggregate value exists at that stage
CWHERE एक बार में केवल एक ही शर्त ले सकता हैWHERE can take only one condition at a time
Daggregate function केवल ORDER BY में ही चल सकते हैंAggregate functions can be used only in ORDER BY