You are on page 1of 23
SQL Questions Eo Peat Cra) eer yr BS Ela Ory Cl hl) regard frac 1) Mock Tests ad Veeco Creed exer D> Download App Question 1: View this Question Online > Database table by name Employee_Records is given below Employee Manager Salary Naresh Hari 1000.00 Suresh Shyam 5000.00 Mahesh Hari 7000.00 What is the output of the following SQL query? z SELECT Count(*) FROM ~% ( (SELECT Employee, Manager FROM Employee_Records) AS SNATURAL JOIN = (SELECT Manager, Salary FROM Employee_Records) AST ); teers] Hem Come] Rela e Leela TA lol g ® ccd Sa) Answer (Detailed Solution Option 3:5 SQL Question 1 Detailed Solution Correct answer is Option C Key Points Oke will be contents of temporary table S Employee Manager Naresh Hari Suresh Shyam e Mahesh Hari Following will be contents of temporary table T Managet Salary Hari 1000.00 ~ Shyam 5000.00 Hari 7000.00 + Following will be the result of natural join of above two tables. + The key thing to note is that the natural join happens on column name with same name which is Manager in the above example. + “Hari” appears two times in Manager column, so there will be four entries with Manager as “Hari", Employee Manager Salary Naresh Hari 1000.00 Naresh Hari 7000.00 Suresh Shyam 5000.00 Mahesh Hari — 10000.00 Mahesh Hari 7000.00 ieee ae ac Start Complete Exam Preparation clr Pes 3) Nie DOS Cierny (ere Download App Question 2: View this Question Online > Table A Id Name Age 12 Reena 60 15 Meena 24 99 Teena 11 Table B Id_Name Age . 15 Meena 24 22g 40 98 Teena 20 99 Teena 11 Table C Id Phone Area 10 2200 02 99 2100 01 How many tuples does the result of the following SQL query contains using tables A.B and C SELECT A.id FROMA WHERE A.age > ALL (SELECT B.age FROM B WHERE B. name = "Reena" Answer (Detailed Solution Below) Option 4:3 ~ SQL Question 2 Detailed Solution Correct answeris option D * Important Points + “ALL' is the A Age should be greater than all the values returned by the subquery + There is no entry with name “Reena” in table B, So the subquery will return NULL. + Ifa subquery returns NULL, + then the condition becomes true for all rows of A. + Soall rows of table A are selected. ee ee eee ee Start Complete Exam Preparation CRE oe aa Pras rear i ia ea cred cores Download App pao Question 3: fr View this Question Online > Which of the following statements are False about an SQL query? A: An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause B: An SQL query can contain a HAVING clause only ifit has a GROUP BY clause C: All attributes used in the GROUP BY clause must appear in the SELECT clause es used in the GROUP BY clause nead to appear in the SELECT clause 2. Aand D 3. Bandc 4. BandD Answer (Detailed Solution Below) Option 2: Aand D ‘SQL Question 3 Detailed Solution © Key Points + HAVING clause can also bette with aggregate function + If We use a HAVING clause with a GROUP BY clause, « the HAVING condition applies to all rows that satisfy the search condition. + In other words, all rows that satisfy the search condition make up a single group. + Not all attributes used in the GROUP BY clause need to appear in the SELECT clause + if We use Group By clause must, there are limitations on what we can put into the Select clause The Correct Answer is option 2. & eee ic Slam CeCe ell) eee Oats aes ety DOS iene researc a Ere Download App Question 4: View this Question Online > Which of the following is used to sort the result set in a specific order? 1. ORDERBY | + 3. WHERE 4, JOIN Answer (Detailed Solution Below) Option 1: ORDER BY cf ‘SQL Question 4 Detailed Solution ORDER BY is used to sort the result setin @ specific order. It is used to sort the result set by one or more columns in ascending or descending order. The ORDER BY clause must be the last clause in a SELECT statement, and it can only be used in SELECT statements, not in UPDATE or DELETE statements. GROUP BY is used t ke, Ny set by one or more columns. The GROUP BY clause groups rows based on the values in one of rmeFe-columns and, typically, is used in combination with aggregate functions to return a single result row for each group. JOIN is used to combine rows from two or more tables based on a related column between them. It can be used to retrieve data from multiple tables as if the data were coming from a single table, WHERE clause is used to filter the result set of a SELECT, UPDATE, DELETE statement. It is used to specify @ condition that rows have to meet in order to be selected or affected. Cad Teer har Start Complete Exam Preparation CR eae? call hee Fb ie Dearie) rClasses Question Bank Download App Exc Question 5: > 2 View this Question Online > of’ Which clause is usad to grou one or more columns? 1. WHERE xe? 2 Fi 3. GROUP BY 4. ORDERBY Answer (Detailed Solution Below) Option 3: GROUP BY ‘SQL Question 5 Detailed Solution c) GROUP BY is used to group the result set by o: ‘The GROUP BY clause groups rows based In one or more columns and, typically, is used in combination with aggregate func’ single result row for each group WHERE clause is used to specify a condition that ro jesult set of a SELECT, UPDATE, DELETE statement. It is used to ave to meet in order to be selected or affected. ORDER BY is used to sort the result set in a specific order. Itis used to sort the result set by one or more columns in ascending or descending order. The FROM clause is used to specify the table or tables from which to retrieve the data and it is usually one of the first clauses ina SELECT statement. Top SOL MCO Objective Questi e eee any Racin) AS Ea ery ele LiCl) Cae a mic Mi sterClasse: Question Bank Download App Exon) Question 6 Answer (Detailed Solution Below) Option 3: * SQL Question 6 Detailed Solution The * symbol is used to see every column of a table. For Example, Let us consider a table Table1 [iD [NAME AGE [ADDRESS [SALARY Bijnor Cera ests View this Question Online > If you want to fetch only some specific columns from the table, then we'can use this query, Select ID,NAME,AGE from Tablet; _// Syntax is Select (column_namel, coloumn_name2.....coloum_name) from table_name; > If you want to fetch all the fields of the Table’ table, then you should use the following query , ‘Select * from Tablet; _// Syntax is Select * from table_name; Sanne 115000 133000 40000 Therefore Option 3 is correct eRe eer Roca) Start Complete Exam Preparation Poe apa ea cae to pO caery eres Download App Question 7 What is the full form of SQL? 1. Simple Query Language. 2 fa are 3. Structured Query Language 4. Structured Queuing Lexicon Answer (Detailed Solution Below) Option 3 : Structured Query Language View this Question Online SQL Question 7 Detailed Solution © Key Points qe ‘SQL (Structured Query Language) is a standardized programming language that's used to manage relational databases and perform various operations on the data in them. ... SQL became the de facto standard programming language for relational databases after they emerged in the late 1970s and early 1980s. + SQL is regularly used ly by database administrators, but also by developers writing data integration scripts and data analysts looking to set up and run analytical queries. + The uses of SQL incluicle modifying database table and index structures, adding, updating and deleting rows of data; and retrieving subsets of information from within a database for transaction processing and analytics applications. Hence the correct answer is Structured Query Language. & PS b A India’s #1 Learning Platform Start Complete Exam Preparation ca) eC 7 Es re Download App Question 8 View this Question Online > Properties of ‘DELETE’ and ‘TRUNCATE’ commands indicate that 1, After the execution of TRUNCATE’ operation, COMMIT, and ROLLBACK statements can be performed to retrieve the lost data, while DELETE’ does not allow it. 2. After the execution of (DELETE! and TRUNCATE’ operation retrieval is easily possible for the lost data r r on of ‘DELETE’ operation, COMMIT and ROLLBACK statements can be to retrieve the lost data, while TRUNCATE do not allow it 4. After the execution of ‘DELETE’ and ‘TRUNCATE’ operation no retrieval is possible for the lost data Answer (Detailed Solution Below) Option 3 : After the execution of ‘DELETE’ operation, COMMIT and ROLLBACK statements can be performed to retrieve the lost data., while TRUNCATE do not allow it SQL Question 8 Detailed Solution TRUNCATE + ls a DDL command hence it cannot be rolled back. + It resets the identity of the table and locks that state of the table. + Hence, Commit and Rollback will have no effect after TRUNCATE. DELETE + Isa DML command hence it can be rolled back + It does not rest the cia itjust locks the table row + Hence Commit and Rollbai have effect depending on the lock techniques used, Hence, it can be said that after the execution of ‘TRUNCATE operation, COMMIT, and ROLLBACK statements cannot be performed to retrieve the lost date, while ‘DELETE’ allows it. It can also be said that after the execution of ‘DELETE’ operation, COMMIT and ROLLBACK statements can be performed to retrieve the lost data, while TRUNCATE does not allow it NOTE In official ISRO CS 2020, both option 1 and3 were correct and hence option is slightly modified to get only correct answer. a Tee an eae) Start Complete Exam Preparation Rea ess ca Pears fabecc es) pei DU (ree euicns Download App Question 9 View this Question Online > Consider a relational database containing the following schemes. Catalogue sno | pno | Cost st | Pi | 150 si | p2 | 50 $1 | P3 | 100 s2 | Pa | 200 $2 | P5 | 250 $3 | P1 | 250 s3 | p2 | 150 $3 | PS | 300 $3 | P4 | 250 Suppliers ae location M/s Royal furniture Delhi $2. | M/s Balaji furniture Bangalore $3 | M/s Premium furniture Chennai Parts pno| Pname | Part spec P1 | Table Wood P2 | Chair Wood P3 |Table | Steel P4 | Almirah | Steel PS | Aimirah | Wood ‘The primary key of each table is indicated by underling the constituent fields, SELECT s.sno, s.sname FROM Suppliers s, Cataloque c WHERE s.sno = ¢.sno AND The number of rows returned by the above SQL query is Answer (Detailed Solution Below) Cost > (SELECT AVG (cost) FROM Cataloque WHERE pno = ‘P4’ GROUP BY pno); Option 1:4 SQL Question 9 Detailed Solution ae Inner Query: SELECT AVG (cost) FROM Catalogue WHERE pno = 'P4’ GRO. 00 The execution of the inner query gives the average of the cost of parts with part-id P4 Output: Avg (cost) 225 Outer Query: SELECT s.sno, s sname FROM Suppliers s, Cataloque c WHERE s sno = c.sno AND Cost > (225) The execution of the entire query output the following table: sno sname s2 Mrs Balaji furniture $3 M/s Premium furniture S3 M/s Premium furniture 83 M/s Premium furniture Heng, there are 4 rows in the resultant table. Fg ee ec a SSE Ta ery eM ee LiCl) SRR Recetas Oras Practice Pa a Cosa oreo exert Question 10 View this Question Online > Consider the schema Sailors(sid, sname, rating, age) with the following data Rating Herald 71] Vishnu 10 16 741 King 9 35 Archer Flinch For the query SELECT S.rating, AVG(S.age) AS avgage FROM Sailors S Where S.age >= 18 GROUP BY S.rating HAVING 1 < (SELECT COUNT(*) FROM Sailors $2 where S.rating = 2.rating) The number of rows returned is 3.4 of Answer (Detailed Solution Below) xe? Option 4:3 SQL Question 10 Detailed Solution Without "having’ clause query calculates the average age (where age >= 18) and groups by ratings so table returned is: Fog eee ec SS Ea meri ele LiCl) Cea ess rears Practice Py MasterClasses Question Bank Download App Exon arr) Question 11 . View this Question Online > Which of the following represents the three basic SQL DML commands? Update, Delete 2. Insert, Alter, Delete 3. Insert, Update, Create 4. Insert, Update, Delete Answer (Detailed Solution Below) Option 4 : Insert, Update, Delete SQL Question 11 Detailed Solution ‘SQL: Structured Query Language, commonly abbreviated to SQL is a language used in Relational Databases. This mainly focuses on creating a database and executing queries against a database. ‘SQL comprises both data definition and data manipulation language (DML). J» Important Points DML: Data Manipulation Language (DML) is used to modify the instance of the database by inserting, updating, and deleting its data. «Insert into/ values tis usdlgmminsert datato a table, + Update/set/were:-Itis used tolUpuate existing data within a table. + Delete from / where- Itis used to telete records from a database table. ©; Additional Information Data Definition Language (DDL):- it is used to design and modify the database schema, * Create: It is used to create new databases, tables, and views from RDBMS. * Drop: It is used to drop databases, tables, and views. + Alter: It is used to modify database schema from RDBMS 5 India’s #1 Learning Platform Start Complete Exam Preparation CBee cocoa Pars are eas DUS tiery Question Bank Diora Download App Question 12 View this Question Online > SELECT operation in SQL is equivalent to 1. the selection operation in relational algebra 2. the selection operation in relational algebra, except that SELECT in SQL retains duplicates 3. the projection operation in relational algebra 4. the projection operation in relational algebra;except that SELECT in SQL retains duplicates ‘Answer (Detailed. Solution Below) Option 4 : the projection operation in relational algebra, except that SELECT in SQL retains duplicetes a Question 12 Detailed Solution Select operation is equivalent to the projection operstion in relational algebra, except that select in ‘SQL retains duplicates and on the contrary projection removes the duplicates. xe” cok Col Fog eee ec SSE a ery ele LiCl) Dees rae ee ejei CCS ciey (ores ic Download App Exons) Question 13 View this Question Online > Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause R: Allattributes used in the GROUP BY clause must appear in the SELECT clause S:Not al attributes used in the GROUP BY clause need to appear in the SELECT clause 1. PandR Vist yh 2. Band S Wine 4. QandS Answer (Detailed Solution Below) Option 3: QandR SQL Question 13 Detailed Solution The correct answer is option 3 EXPLANATION: GROUP BY clause: + The GROUP BY statement groups rows that have the same values into summary rows, like “find the number of customers in each country’. + The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns. Syntax: ‘SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) Lg Example: SELECT COMPANY, COUNT(*) * FROM PRODUCT_MAST ‘ GROUP BY COMPANY Therefore all atiributes used in the GROUP BY clause must appear in the SELECT clause HAVING clause: a + HAVING clause is used to specify a sears condition for a group or an aggregate. + Having is used in a GROUP BY clause + If you are not using GROUP BY clause then you can use HAVING function like a WHERE clause. Syntax: SELECT column1, column2 FROM table_name WHERE conditions GROUP BY column], column2 HAVING conditions ORDER BY column1, column2; Example: ‘SELECT COMPANY, COUNT(*) FROM PRODUCT_MAST GROUP BY COMPANY HAVING COUNT(*)>2; oe an SQL query can contain a HAVING clause only if it has a GROUP BY clause, Colifligion Pol The answer is as per standard SQL & india’s #1 Learning Platform @ aswioeers Start Complete Exam Preparation Eyota yee Practice ey Mock Tests erhaienny eee Download App Question 14 Y View this Question Online > attribute is used to restart the numbering in an ordered list. 1. Type at 2. or J 3. Start 4. Number Answer (Detailed Solution Below) Option 8: Start SQL Question 14 Detailed Solution ie type attribute specifies the type of element.For Ex:For bution lements, the type attribute specifies the type of button, ="submit" value="Submit'>Submit he order property specifies the order of a flexible item relative to the rest of the flexible items inside the Same itainer..Ex:document.getElementByld("myRedDIV").style.order| he start attribute specifie lan ordered list Ex: start value of the first list item in S|" pumber’> It defines a field for entering a number.Ex: Nui rd India’s #1 Learning Platform STC Ta mere) ed yD Pie ae mao tai Cres earn Patri Download App Deco What result setis returned from the following St A, Select customer_name, telephone O From customers O Where city in (Jaipu 5 It son and telephone of all customers. 2. The customer_name and telephone of all customers Living in Jaipur, Delhi and Agra. 3. The customer_name and telephone of all customers Living in either Jaipur Delhi or Agra. Question 15, > ~ View this Question Online > O* WO 4. The customer_name and telephone of all customers who are not living in Jaipur, Delhi or Agra. Answer (Detailed Solution Below) Option 3: The customer_name and telephone of all customers Living in either Jaipur te) 9 ‘SQL Question 15 Detailed Solution NA G —_ C2 matches any value in a list of values. It The SQLIN condition allows us to easily test if reduces the need for multiple OR condition Explanation: Given SQL query : Select customer_name, telephone From customers Where city IN (Jaipur’, Delhi’, Agra’) ; As the operator used is IN so, it will result in the customer name and telephone of all customers living in the city either Jaipur, Delhi or Agra.

You might also like