0% found this document useful (0 votes)
153 views5 pages

SQL Quiz: Functions and Queries

This document contains 20 multiple choice questions about SQL concepts like single row functions, subqueries, joins, aggregation functions and wildcards. The questions cover topics like valid placements of subqueries, uses of wildcards, comparison operators that can be used with multiple row queries, and properties of functions like COALESCE, MAX, MIN. The answers provided are also in multiple choice format with one option being the correct answer in each case.

Uploaded by

Neeraj Tripathy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views5 pages

SQL Quiz: Functions and Queries

This document contains 20 multiple choice questions about SQL concepts like single row functions, subqueries, joins, aggregation functions and wildcards. The questions cover topics like valid placements of subqueries, uses of wildcards, comparison operators that can be used with multiple row queries, and properties of functions like COALESCE, MAX, MIN. The answers provided are also in multiple choice format with one option being the correct answer in each case.

Uploaded by

Neeraj Tripathy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Q 1 - Which of the following is not true about single row functions?

A - They operate on single rows only and return one result per row.
B - They accept arguments that could be a column or any expression.
C - They cannot be nested.
D - They may modify the data type.
Answer : C
Q2- A subquery can be placed in which of the SQL clauses?
A - The WHERE clause
B - The HAVING clause
C - The FROM clause
D - All of the above.
Answer : D
q3-The
A.
B.
C.
D.

wildcard in a WHERE clause is useful when?


An exact match is necessary in a SELECT statement.
An exact match is not possible in a SELECT statement.
An exact match is necessary in a CREATE statement.
An exact match is not possible in a CREATE statement.

Answer: Option B
q4. The || is is an example of what function SELECT last_name||','||first_name||
' '||middle_name from employee;
[Link]
[Link]
[Link]
[Link]
[Link] of the above
Ans D
[Link] want all dates when any employee was hired. Multiple employees were hired
on the same date and you want to see the date only once.
query-1 Select distinct hiredate from [Link] order by hiredate;
Query-2 Select hiredate from [Link] group by hireddate order by hiredate;
Which of the above query is valid?
A)Query-1
B)Query-2
C)Both
Ans:Cs except for
[Link] aggregate functions ignore NULLs excepts for....
A)Distinct
B)Count(*)
c)Average()
D)None of Above
Ans:D

[Link] the purpose of ........ null values are considered equal to other nulls a
re grouped together into a single result row.
a)Having
b)Group By
c)Both of above
D)None of above
Ans:B
Q8. Which of the following comparison operators could be used in a multiple row
query?
A - IN operator
B - ANY operator
C - ALL operator
D - All of the above
Answer : D
[Link] the following schema STUDENTS(student_code, first_name, last_name, email,
phone_no, date_of_birth, honours_subject, percentage_of_marks);
Which of the following code will create a simple view named all_marks_english th
at contains the names and percentage of marks of the students in the honours_sub
ject Eng01 ?
A - create view all_marks_english as select first_name, last_name, percentage_of
_marks from students where honours_subject = Eng01 ;
B - create view all_marks_english as ( first_name, last_name, percentage_of_mark
s from students where honours_subject = Eng01 );
C - select view all_marks_english as select first_name, last_name, percentage_of
_marks from students where honours_subject = Eng01 ;
D - None of the above.
Ans:A
q10 - Consider the following schema STUDENTS(student_code, first_name, last_name, email,
phone_no, date_of_birth, honours_subject, percentage_of_marks);
Which of the following query would display the full name of a student, with a co
lumn heading "Name"
A - select first_name, last_name as

Name from students;

B - select Name from students;


C - select first_name || last_name as

Name from students;

D - select first_name, last_name from students;

Answer : C
Q11- Which of the following is not true about the COALESCE function?
A - It takes multiple alternate values.
B - It returns the first non-null expression in the parameter list.
C - It returns the first value in the parameter list if it is null.
D - None of the above.
Show Answer
Answer : C
[Link] of the following is not true about the MAX and MIN functions?
A - Both can be used for any data type.
B - MAX returns the maximum value.
C - MIN returns the minimum value.
D - All are true.
Show Answer
Answer : D
[Link] of the following is true about subqueries?
A - Subqueries could be used for Top-N analysis.
B - Subqueries can be of two types
.

single-row subquery and multiple-row subquery

C - The outer and inner queries can get data from different tables.
D - All of the above.
Answer : D
q-14. Which of the following is not true about multiple-row subqueries?
A - Multiple row subqueries return multiple rows from the outer SELECT statement
.
B - Multiple row subqueries return multiple rows from the inner SELECT statement
.
C - Multiple row subqueries use multiple-row comparison operators.
D - All of the above.
Answer : B
[Link] the following schema -

STUDENTS(student_code, first_name, last_name, email,


phone_no, date_of_birth, honours_subject, percentage_of_marks);
Which of the following query would display names of all the students whose honou
rs subject is English and percentage of marks more than 80, or honours subject i
s Spanish and percentage of marks more than 80?
A - select first_name, last name from students where (honours_subject =
honours_subject = Spanish ) and percentage_of_marks > 80;
B - select first_name, last name from students where honours_subject =
honours_subject = Spanish and percentage_of_marks > 80;

English
English

or
or

C - select first_name, last name from students where (honours_subject =


honours_subject = Spanish and percentage_of_marks > 80);

English

D - select first_name, last name from students where (honours_subject =


r honours_subject = Spanish and percentage_of_marks > 80;

English ) o

Answer : A
q-16 - Which of the following query will result in an error?
A - select dept_id, avg(salary) from employees group by dept_id;
B - select avg(salary) from employees group by dept_id;
C - select dept_id, job_id, avg(salary) from employees group by dept_id, job_id;
D - select dept_id, count(name) from employees;
Answer : D
q-17 Consider the following schema STUDENTS(student_code, first_name, last_name, email,
phone_no, date_of_birth, honours_subject, percentage_of_marks);
Which of the following query would display names of all the students whose email
ids are not provided?
A - select first_name, last name from students where email = 0;
B - select first_name, last name from students where email =

C - select first_name, last name from students where email is null;


D - select first_name, last name from students where email = null ;
Answer : C
q-18 Consider the following schema HONOURS_SUBJECT(subject_code, subject_name, department_head);
LOCATIONS(subject_code, department_name, location_id, city);
Select the right query for retrieving records from the tables HONOURS_SUBJECT an
d LOCATIONS with a left outer join
A - select h.subject_name, l.department_name, h.department_head, [Link] from hon
ours_subject h left outer join location l on(h.subject_code = l.subject_code);

or

B - select h.subject_name, l.department_name, h.department_head, [Link] from hon


ours_subject h left outer join location l on(subject_code);
C - select h.subject_name, l.department_name, h.department_head, [Link] from hon
ours_subject h left join location l on(h.subject_code = l.subject_code);
D - None of the above.
Answer : A
q-19
The result of a SQL SELECT statement is a(n) ________ .
A.
report
B.
form
C.
file
D.
table
Answer: Option D
q-20
The SQL
A.
B.
C.
D.

-92 wildcards are ____ and ____ .


asterisk (*); percent sign (%)
percent sign (%); underscore (_)
underscore(_); question mark (?)
question mark (?); asterisk (*)

Answer: Option B

Common questions

Powered by AI

Creating a view involves defining a stored SELECT query that may not include execution but sets a blueprint for querying. A view abstracts query logic, enabling repeated use without rewriting. In contrast, a regular SELECT query executes immediately and doesn't persist .

Using the DISTINCT keyword in a SQL query ensures each hiring date appears once, even if multiple employees share the same date. An example query is: SELECT DISTINCT hiredate FROM hr.employee ORDER BY hiredate .

Most SQL aggregate functions, such as SUM and AVG, ignore NULL values. However, COUNT(*) is an exception as it includes NULLs when counting rows .

Multiple-row subqueries might return unexpected results if not properly structured. They should return multiple rows from the inner SELECT, using appropriate multiple-row comparison operators like ANY or ALL, otherwise, they may lead to logical errors or mismatches in queries .

Incorrect use of WHERE and HAVING clauses in subqueries can lead to logical errors or inefficient queries. The WHERE clause filters before grouping; HAVING filters after. Misuse can lead to filtering errors or returning incorrect result sets, especially with conditions that rely on aggregate functions .

SQL wildcards are useful when an exact match is not possible in a SELECT statement, enabling flexible searching through patterns rather than specific values .

A misconception about single row functions is that they cannot be nested. In fact, single row functions can be nested to form complex expressions .

In multiple-row SQL queries, the IN, ANY, and ALL operators can be used to compare values against a set of results from an inner query, enabling more complex logical comparisons across multiple rows .

The '||' operator in SQL is used for concatenation, combining two or more strings into a single string. For instance, concatenating first name, last name, and a middle name into a single output .

Subqueries can be used within SQL queries in various ways, such as fetching data based on the results of another query. They can be placed in the WHERE, HAVING, and FROM clauses, allowing complex querying by nesting queries within larger ones .

You might also like