# Querying and SQL Functions Class 12 Informatics Practices Exam Questions

Please refer to Nationalism in India Class 12 Querying and SQL Functions Exam Questions provided below. These questions and answers for Class 12 Social Science have been designed based on the past trend of questions and important topics in your class 12 Social Science books. You should go through all Class 12 Querying and SQL Functions Important Questions provided by our teachers which will help you to get more marks in upcoming exams.

## Class 12 Querying and SQL Functions Exam Questions Nationalism in India

Class 12 Querying and SQL Functions students should read and understand the important questions and answers provided below for Nationalism in India which will help them to understand all important and difficult topics.

1. A relation Vehicles is given below :

Question: Display the average price of each type of vehicle having quantity more than 20.
Answer: Select avg(price), type from vehicles group by type having qty>20;

Question: Count the type of vehicles manufactured by each company.
Answer: Select count(type),type,company from vehicles group by company;
Question: Display the total price of all the types of vehicles.
Answer: Select sum(price) from vehicles group by type

Question: In a database there are two tables : Write MYSQL queries for (i) to (iii)
Table : Item

(i)To display ICode, IName and VName of all the vendors, who manufacture “Refrigerator”.

(ii)To display IName, ICode, VName and price of all the products whose price >=23000

(iii)To display Vname and IName manufactured by vendor whose code is “P04”.

Answer: (i)Select ICode, IName,VName from Item I,Vendor V where I.Vcode=V.VCode and IName=’Refrigerator’

(ii)Select IName, ICode,VName from Item I,Vendor V where I.Vcode=V.VCode and Price>=23000

(iii)Select VName,IName from Item I,Vendor V where I.Vcode=V.VCode and
I.VCode=’P04′

Question: Considering the Visitor table data, write the query for

(i) Write a query to display VisitorName, Coming From details of Female Visitors with Amount Paid more than 3000

(ii) Write a query to display all coming from location uniquely

(iii) Write a query to insert the following values- 7, „Shilpa‟,‟F‟,‟Lucknow‟,3000

(iv) Write a query to display all details of visitors in order of their AmountPaid from highest to lowest

(v) Write a query to display visitor name with annual amount paid
Answer: (i) Select VisitorName,ComingFrom from Visitor
AmountPaid>3000
(ii) Select distinct ComingFrom from Visitor
(iii) insert into visitor values(7,’Shilpa’,’F’,’Lucknow’,3000)
(iv) Select * from visitor order by AmountPaid desc
(v) select visitorname, amountpaid*12 rom visitor;

Question: Write a function in SQL to find minimum and maximum value of a column in a table.
Answer: MIN ( ) and MAX ( ) aggregate functions in SQL.

Question: Which of the following is used to arrange data of table?
a. ARRANGE BY
b. ORDER BY
c. ASC
d. DESC

Answer: b. ORDER BY

Question: In MYSQL, write the query to display list of databases store in it.
Answer: SHOW DATABASES;

Question: Consider the following query:
SELCT emp_name from Employee WHERE dept_id _______NULL;
a. =
b. LIKE
c. IS
d. ==
Answer: c. IS

Question:  For the given table CLUB
Table: CLUB

What will be the degree and cardinality of table?
Answer: Degree is Number of attributes or columns which will be 7
Cardinality is Number of tuples or rows in a table which will be 10.

Question: Which of the following is not a valid clause in SQL?
a. MIN
b. WHERE
c. BETWEEN
d. GROUP BY

Answer: a. MIN is a function in SQL (not a clause like rest of the options)

Question: Which command is used to add new row in a table?
a. Add
b. Insert
c. Update
d. None of the above
Answer: b. Insert command is used to add new row in a table

Question: What is the full of SQL?
Answer: Structured Query Language

Question: What is the difference between CHAR and VARCHAR datatypes in SQL?
Answer: • CHAR data type is used to store fixed-length string data and the VARCHAR data type is used to store variable-length string data.
• The storage size of the CHAR data type will always be the maximum length of this data type and the storage size of VARCHAR will be the length of the inserted string data. Hence, it is better to use the CHAR data type when the length of the string will be the same length for all the records.
• CHAR is used to store small data whereas VARCHAR is used to store large data.
• CHAR works faster and VARCHAR works slower.

Question: Consider the following table Student and give output of following questions:

a. SELECT * FROM Student WHERE Grade = ‘B’ ;
b. SELECT MAX( Marks) FROM Student;
c. SELECT Name, Marks FROM Student WHERE Subject IN (‘English’, ‘Science’);
d. SELECT RollNo, Subject FROM Student WHERE Marks>= 85;///
Answer:

Question: Write SQL commands for the following on the basis of given table WORKER
Table: Worker

a .To display first and last name of workers having salary greater than or equal to 90000.
b.To display details of workers working in HR department and Admin department
c.To find average of Salary in table worker
d.To Change first name of worker to ‘Satisha’ whose worker id is 007
Answer:  SELECT First_Name, Last_Name FROM Worker WHERE Salary >=90000;
a
b  SELECT * FROM Worker WHERE Department IN (‘HR’, ‘Admin’);
c SELECT AVG(Salary) FROM worker;
d UPDATE Worker SET First_Name=’Satisha’ WHERE Worker_Id=007;

Question: Which of the following clause can be used with Group By?
a) Having
b) Where
c) Order by
d) None
Answer: Having and Order By

Question: Write down name of four functions that can be used with Group by?
Answer:
Count(), sum(), min(), max()

Question: What is Group By clause?
Answer: The GROUP BY Clause is utilized in SQL with the SELECT statement to organize similar data into groups. It combines the multiple records in single or more columns using
some functions. Generally, these functions are aggregate functions such as min(),max(),avg(), count(), and sum() to combine into single or multiple columns.

Question: Why we use Having clause?
Answer: The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

Question: What is the purpose of Group By clause?
Answer: Group by clause is used in a Select statement in conjunction with aggregate functions to group the result based on distinct values in column.

Question: You have a table “Company” having column cno, cname, department and salary. Write SQL statement to display average salary of each department.
Answer: SELECT department, avg(salary) from company Group by department;

Question: Can a Group by clause be used for more than one column? If yes, given an example.
Answer: Yes. Select name, grade, class From student Group by Class, grade

Question: Anis has given the following command to arrange the data in ascending order of date.
Select * from travel where order by tdate;
But he is not getting the desired result.
Help him by choosing the correct command.
a. Select * from travel order by tdate;
b. Select * from travel in ascending order;
c. Select tdate from travel order by tdate;
Answer: Select * from travel order by tdate;

Question: Choose the correct query to count the number of codes in each code type from travel table?
i. select count(code) from travel ;
ii. select code, count(code) from travel group by code;
iii. select code, count( distinct code) from travel;
iv. select code, count( distinct code) from travel group by code;

Choose the correct option:
a. Both (ii) and (iii)
b. Both (ii) and (iv)
c. Both (i) and (iii)
d. Only (ii)
Answer: b

Question: Which of the following clause cannot be used with WHERE?
a) IN
b) Between
c) Group by
d) None of the above
Answer: Group By

Question: Which of the following clause can be used with Group By?
a) Having
b) Where
c) Order by
d) None
Answer: Having and Order By

Question: Write down name of four functions that can be used with Group by?
Answer: Count(), sum(), min(), max()

Question: What is Group By clause?
Answer: The GROUP BY Clause is utilized in SQL with the SELECT statement to organize similar data into groups. It combines the multiple records in single or more columns using some functions. Generally, these functions are aggregate functions such as min(),max(),avg(), count(), and sum() to combine into single or multiple columns.

Question: Why we use Having clause?
Answer: The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

Question: What is the purpose of Group By clause?
Answer: Group by clause is used in a Select statement in conjunction with aggregate functions to group the result based on distinct values in column.

Question: You have a table “Company” having column cno, cname, department and salary. Write SQL statement to display average salary of each department.
Answer: SELECT department, avg(salary)
from company Group by department;

Question: Can a Group by clause be used for more than one column? If yes, given an example.
Answer: Yes.
Select name, grade, class
From student
Group by Class, grade

Question: Anis has given the following command to arrange the data in ascending order of date.
Select * from travel where order by tdate;

But he is not getting the desired result.
Help him by choosing the correct command.
a. Select * from travel order by tdate;
b. Select * from travel in ascending order;
c. Select tdate from travel order by tdate;
Answer: Select * from travel order by tdate;

Question: Choose the correct query to count the number of codes in each code type from travel table?
i. select count(code) from travel ;

ii. select code, count(code) from travel group by code;
iii. select code, count( distinct code) from travel;
iv. select code, count( distinct code) from travel group by code;
Choose the correct option:
a. Both (ii) and (iii)
b. Both (ii) and (iv)
c. Both (i) and (iii)
d. Only (ii)
Answer: B

Question: Identify the name of connector to establish bridge between Python and MySQL
1. mysql.connection
2. connector
3. mysql.connect
4. mysql.connector
Answer: 4. mysql.connector

Question: Which function of connection is used to check whether connection to mysql is successfully done or not?
import mysql.connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required as passed if :
print(“Connected!”)
else:
print(“ Error! Not Connected”)
a) con.connected()
b) con.isconnected()
c) con.is_connected()
d) con.is_connect()
Answer: c) con.is_connected()

Question: What is the difference in fetchall() and fetchone()?
Answer: fetchall() function is used to fetch all the records from the cursor in the form of tuple.
fetchone() is used to fetch one record at a time. Subsequent fetchone() will fetch next records. If no more records to fetch it return None.

Question: The kind of join that will return all the rows from the left table in combination with the matching records or rows from the right table.
Answer: Left Join