SQL_MCQs
SQL_MCQs
WHERE Clause
Which SQL query retrieves employees earning more than $50,000?
Arithmetic Operators
What will be the output of SELECT 10 + 5 * 2;?
a) 30
b) 20
c) 25
d) 15
**Answer:** b) 20
Logical Operators
Which of the following correctly filters records where age is between 20 and 30?
Date Functions
Which function returns the current date?
a) GETDATE()
b) CURRDATE()
c) NOW()
d) Both a and c
**Answer:** d) Both a and c
Numeric Functions
What does ROUND(23.6789, 2) return?
a) 23.67
b) 23.68
c) 23.679
d) 23.6
**Answer:** b) 23.68
String Conversion
Which function converts a number to a string in SQL?
a) CAST()
b) TO_CHAR()
c) CONVERT()
d) All of the above
a) CHECK
b) FOREIGN KEY
c) UNIQUE
d) INDEX
a) NOT NULL
b) PRIMARY KEY
c) UNIQUE
d) FOREIGN KEY
Subqueries
What is the result of using a subquery in the FROM clause?
a) A table
b) A column
c) A single value
d) An error
**Answer:** a) A table
Ordering
How do you sort employees by salary in descending order?
a) INNER JOIN
b) LEFT JOIN
c) RIGHT JOIN
d) FULL JOIN
Updatable Views
Which SQL condition allows an updatable view?
Non-Updatable Views
Which SQL statement creates a non-updatable view?
a) UNION ALL
b) UNION
c) INTERSECT
d) EXCEPT
**Answer:** b) UNION
EXISTS Clause
What does EXISTS check in a query?
CASE Statement
Which SQL statement correctly uses CASE?
a) SELECT name, CASE WHEN age > 18 THEN 'Adult' ELSE 'Minor' END FROM Students;
b) SELECT name, CASE WHEN age > 18 'Adult' ELSE 'Minor' END FROM Students;
c) SELECT name, CASE age > 18 THEN 'Adult' ELSE 'Minor' END FROM Students;
d) SELECT name, CASE age > 18 'Adult' ELSE 'Minor' END FROM Students;
**Answer:** a) SELECT name, CASE WHEN age > 18 THEN 'Adult' ELSE 'Minor' END FROM
Students;
HAVING vs WHERE
Which clause is used with aggregate functions?
a) WHERE
b) HAVING
c) GROUP BY
d) ORDER BY
**Answer:** b) HAVING
Self-Join
What does a self-join do?