Database Query SQL Function MCQ | MySQL functions MCQ

Latest MCQ for MySQL functions | Database Query SQL Function MCQ helpful for all competitions entrance exams, cucet for computer science

  1. Which of the following is not multiple row function?

    a. Avg()
    b. Sum()
    c. Sqrt()
    d. Both (a) and (b)

Show Answer

c. Sqrt()

  1. SELECT UPPER(SUBSTR(‘Computer System’, 3, 6));
    Gives the output as:


    a. MPU
    b. MPUT
    c. MPUTER
    d. PUT

Show Answer

c. MPUTER

  1. substr( 56434.7812,4,5)  gives the output ______

    a. Will produce error
    b. No Output
    c. 34.78
    d. 4.781

Show Answer

c. 34.78

  1. Write SQL command to display the name of current month 

    a. SELECT MONTH(CURDATE());
    b. SELECT NAMEOFMONTH(CURDATE());
    c. SELECT MONTHNAME(CURDATE());
    d. All of the above

Show Answer

c. SELECT MONTHNAME(CURDATE());

  1. WHERE and HAVING clause can be used interchangeably in SELECT query.

    a. Yes
    b. No
    c. Depends on RDBMS
    d. Not Sure

Show Answer

b. No

  1. Length() is a

    a. Text function
    b. Numeric function
    c. Date function
    d. Aggregate function

Show Answer

a. Text function

  1. Consider the string ‘techtipnow’. Write SQL command to display first five characters

    a. Select left(‘techtipnow’,5);
    b. Select substr(‘techtipnow’,1,5);
    c. Select ltrim(‘techtipnow’,5);
    d. Both (a) and (b)

Show Answer

d. Both (a) and (b)

  1. Write a query to display total no of departments from the given table ‘emp’.
enoenamesalDept
1Ram3400Store
2Rakesh8000Back office
3Prakash6200Back office
4Daya1900Operation
5Pawan3000Operation
6Abdul2800Store
7Simon4500operation

  • a. SELECT COUNT(dept) FROM emp;
    b. SELECT COUNT(DISTINCT (dept)) FROM emp;
    c. SELECT eno, COUNT(dept) FROM emp GROUP BY eno;
    d. SELECT dept, COUNT(ename) FROM emp  GROUP BY dept;

Show Answer

b. SELECT COUNT(DISTINCT (dept)) FROM emp;

  1. Surendra have been asked to differentiate between WHERE and HAVING clause by his teacher. He wrote two statements for the same as given below. you have to state which statement is True and which is False.

    (i) Both WHERE and HAVING clause can contain aggregate functions.
    (ii) WHERE clause can used without GROUP BY clause but HAVING can not.

    a. (i) True,(ii) False
    b. (i) False, (ii) True
    c. Both are True
    d. Both are False

Show Answer

b. (i) False, (ii) True

  1. Consider following table ‘item’ and predict the output of following:
    Select sum(length(title)) from item where author = ‘Dixit’ Group By Author
NoTitleAuthorTypeDOPQtyprice
1Data StructureDixitDS12/10/20034300
2Computer StudiesFrenchFND11/11/2003275
3Advanced PascalShildtPROG01/12/20034350
4Dbase DummiesPalmerDBMS23/12/20035130
5Mastering C++DixitPROG08/01/20043295
6Guide NetworkFreedNET10/02/20043200
7Mastering FoxproSeigalDBMS17/02/20042135
8DOS GuideNortonOS11/03/20043175
9Basic for beginnerMortonPROG21/04/2004340
10Mastering C ProgramsDixitPROG06/05/20041195

  • a. 45
    b. 47
    c. 3
    d. 15

Show Answer

b. 47

  1. For given string ‘techtipnow’ sanjay wants to display the position of ‘p’. what code he should write to get this?

    a. Select mid(‘techtipnow’,’p’);
    b. Select substr(‘techtipnow’,’p’);
    c. Select instr(‘techtipnow’,’p’);
    d. All of the above

Show Answer

c. Select instr(‘techtipnow’,’p’);

  1. Chunnu has created following table to store the records:
    Table : Loan
AccnoAccnameAmountLaontypeInterest
TT101Sanjeev55000Auto7.65
TT102Abhishek300000Home7.1
TT103Shagun12000Personal9.85
TT104Gunjan30000Auto6.90
TT105Jyoti100000Home9.10

He wants to calculate average interest rate of ‘Auto’ type of laon. Help him to do so.

a. select avg(interest) from loan where loantype = ‘auto’;
b. select avg(interest) from loan where loantype in (‘auto’);
c. Select avg(interest) from loan where loantype = ‘auto’ group by loantype;
d. All of above

Show Answer

d. All of above

  1. Which of the following is not a single row function?

    a. Mod()
    b. Ltrim()
    c. Year()
    d. Max()

Show Answer

d. Max()

  1. Predict the output of ‘Select Round(33792.845,-3);

    a. 34000
    b. 33000
    c. 33800
    d. 33793

Show Answer

a. 34000

  1. Rahul has created a table book with following columns-
    Bcode, bname, price, publication
    He wants to display lowest price of book publication wise. He wrote following code
    Select publication, min(price) from book;
    But he did not get the desired result. Help him to get the desired result by rewriting query.

    a. Select min(price), publication from book;
    b. Select publication, min(price) from book group by publication;
    c. Select publication, min(price) from book having publication
    d. All of above

Show Answer

b. Select publication, min(price) from book group by publication;

  1. Consider the following table Hospital given below and answer your question from (i)-(v).
NoNameAgeDepartmentDeteofadmChargesGender
1Suman56Surgery21/01/21300F
2Subhash65ENT12/12/20250M
3Raheem43Orthopedic19/02/20200M
4Arush24Surgery11/01/20300M
5Sarita32ENT12/01/20250F
6Guleshwari18Cardiology20/02/20800F
7Kushagra28Cardiology13/01/20800M
8Shilpa24ENT21/02/20250F

Select appropriate SQL command to display name and department of all the male candidates with their date of admission in ascending order.

a. Select name, department from hospital where gender is ‘M’ and order by dateodadm;
b. Select name, department from hospital where gender = ‘M’ and orderby dateofadm;
c. Select name, department from hospital where gender = ‘M’ order by dateofadm;
d. Select name, department from hospital order by dateofadm where gender = ‘M’;

Show Answer

c. Select name, department from hospital where gender = ‘M’ order by dateofadm;

  1. Jamwant intends to group the result set based on some column’s value. Also, it is required that the grouped result should appear in sorted order. In which order should the Jamwant write the two clauses (for sorting and grouping) ?

    a. Select <fieldnames>
    From <table name>
    Order by <fieldname>
    Group by <fieldname>

    b. Select <fieldnames>
    From <table name>
    Group by <fieldname>
    Order by <fieldname>

    c. Both (a) and (b) can be taken
    d. None of these

Show Answer

b. Advance research project agency network

  1. Predict the output of
    LENGTH(RTRIM(“   Techtipnow   “)); [Note: there are 3 space before and after ‘techtipnow’]


    a. 13
    b. 10
    c. 16
    d. 9

Show Answer

b. Select 
    From 
    Group by 
    Order by 

  1. Which of the following can be used to display current date?

    a. Now()
    b. Date()
    c. Curdate()
    d. Both (a) and (c)
    e. All of the above

Show Answer

d. Both (a) and (c)

  1. Name the functions to remove unnecessary leading and trailing space characters comes with string

    a. Left(), right()
    b. Lefttrim(), righttrim()
    c. Ltrim(), rtrim()
    d. Substr(), instr()

Show Answer

c. Ltrim(), rtrim()

  1. Consider the following table ‘Student’ and predict the output of following query:
    Select count(*), count(marks) from Student;
RollnoNameSubjectMarks
1SanjayScience58
2RaviMath89
3GauravMathNull
4VishalScience88
5RahulArt90
6JaishankarScience76

  • a. 6,6
    b. 6,5
    c. 5,6
    d. 5,5

Show Answer

b. 6,5

  1. For given table ‘student’ in Q21, find the output of :
    Select max(marks) + Min(marks) from student where subject = ‘science’;


    a. 134
    b. 146
    c. No Output
    d. Will generate Error

Show Answer

b. 146

  1. Aryan, a database administrator, has grouped records of a table with the help of group by clause. He needs to further filter groups of records generated through group by clause. Suggest suitable clause for it

    a. Where Clause
    b. Having Clause
    c. Both
    d. None of these

Show Answer

b. Having Clause

  1. Predict the output of
    MOD(ROUND(13.9,0),3);                                                 [CBSE IP TERM-2 2022]


    a. 4
    b. 2
    c. 1
    d. 9

Show Answer

b. 2

  1. Consider the following tables Product and Customer.
PIDPNAMEBRANDPRICE
Tp01Telcom powderLAK40
Fw05Face WashABC45
B501Bath soapABC55
Sh06ShampooXYZ120
Fw12Face washXYZ95
CIDCNAMECITYPID
01Cosmetic shopDelhiFw05
02Total healthMumbaiB501
12Live lifeDelhiSh06
15Pretty womanDelhiFw12
10DreamsChennaiTp01

Write SQL command to display customername and products name purchased by customer who lives in Delhi

a. Select cname, pname from customer, product where product.pid = customer.pid having city = ‘delhi’;
b. Select cname, pname from customer, product where product.pid = customer.pid and city = ‘delhi’;
c. Select cname, pname from customer c, product p where p.pid = c.pid and city = ‘delhi’;
d. All of above
e. Both (b) and (c)

Show Answer

e. Both (b) and (c)

  1. Consider the following tables Employee and Job
EidEnameSalesJobid
E1Sanjay lal1100102
E2Ravi batra1200101
E3Jagbir singh1400103
E4Mohit mathur1250102
E5Ashish yadav1450103
JobidTitlesal
101President20000
102Director16500
103Manager12000
104Accountant8000
105Clerk6000

Write SQL queries to display name of employee whose salary is lowest.

a.  Select ename, min(sal) from employees, job where job.jobid = employee.jobid;
b. Select ename, min(sal) from employees, job;
c. Select ename, min(sal) from employee, job having job.jobid = employee.jobid;
d. All of the above

Show Answer

a.  Select ename, min(sal) from employees, job where job.jobid = employee.jobid;

  1. Srikant created the following table ‘Student’ in his database; [CBSE IP TERM 2 2022]
    Table: Student
RollnoNameClassMarks
1Ritika1240
2Angad1235
3Kaveri1142
4Durgesh1221
5Denial1144
6Rabindra1139
7Rabia1128

He now wants to count number of student in each class where the number of student is more than 3. He has executed the following query:
Select max(marks) from student where count(*) >3 group by class;
But he got an error. Help him in writing query correctly

a. Select max(marks) from student group by class having count(*)>3;
b. Select max(marks) from student group by class where count(*) >3;
c. Select count(marks) from student group by class having count(*) >3;
d. Select count(marks) from student group by class where count(*) >3;

Show Answer

c. Select count(marks) from student group by class having count(*) >3;

  1. Write SQL command to display book details of those books purchased on Monday for given table ‘book’
NoTitleAuthorTypeDOPQtyprice
1Data StructureDixitDS12/10/20034300
2Computer StudiesFrenchFND11/11/2003275
3Advanced PascalShildtPROG01/12/20034350
4Dbase DummiesPalmerDBMS23/12/20035130
5Mastering C++DixitPROG08/01/20043295
6Guide NetworkFreedNET10/02/20043200
7Mastering FoxproSeigalDBMS17/02/20042135

a. Select * from book where day(dop) like ‘Monday’;
b. Select * from book where day(dop) = ‘Monday’;
c. Select * from book where dayname(dop) like ‘Monday’;
d. Select * from book where dayname(dop) = ‘Monday’;

Show Answer

d. Select * from book where dayname(dop) = ‘Monday’;

  1. Predict the output of following code :
    SELECT UPPEER(MID(‘techtipnow computers’,10));

    a. techtipnow
    b. TECHTIPNOW
    c. W COMPUTERS
    d. IPNOW COMP

Show Answer

c. W COMPUTERS

  1. Which of the following statement is true about ‘Cartesian Product’?

    a. It is an operation that combines tuples from two relations regardless of whether they have the same values or not.
    b. The degree of resulting relation is calculated as the product of the degrees of both the relation under construction.
    c. The cardinality of resulting relation is calculated as the sum of the cardinality of relations under consideration
    d. All are true

Show Answer

a. It is an operation that combines tuples from two relations regardless of whether they have the same values or not.

  1. Which of the following is not a valid join type?

    a. Equi join
    b. Non equi join
    c. Natural join
    d. Inner join

Show Answer

b. Non equi join

1 thought on “Database Query SQL Function MCQ | MySQL functions MCQ”

  1. Pingback: KVS PGT Computer Science MCQ | KVS Recruitment 2022-23 – techtipnow

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!