OA Exams
Which SQL function returns the total number of rows in a result set?
a) COUNT()b) SUM()c) AVG()d) MAX()
Correct Answer: a) COUNT()
Explanation: The COUNT() function returns the total number of rows in a result set, often used to count rows that meet certain conditions.
Which type of join in SQL combines all rows from two tables, regardless of matching values?
a) FULL JOINb) CROSS JOINc) INNER JOINd) LEFT JOIN
Correct Answer: b) CROSS JOIN
Explanation: A CROSS JOIN returns the Cartesian product of two tables, combining all rows from both tables, regardless of matching values.
Which SQL keyword is used to filter the results of a query based on a condition?
a) WHEREb) HAVINGc) LIMITd) ORDER BY
Correct Answer: a) WHERE
Explanation: The WHERE clause filters the rows returned by a query based on a specified condition.
Which SQL command is used to remove all rows from a table but keep its structure intact?
a) DELETEb) TRUNCATEc) DROP TABLEd) REMOVE TABLE
Correct Answer: b) TRUNCATE
Explanation: The TRUNCATE command removes all rows from a table but retains the table structure for future use.
Which SQL function is used to return the length of a string?
a) LENGTH()b) CONCAT()c) TRIM()d) SUBSTRING()
Correct Answer: a) LENGTH()
Explanation: The LENGTH() function returns the number of characters in a string in SQL.
Which SQL operator is used to return values that do not match a specified pattern?
a) NOT LIKEb) LIKEc) NOT INd) EXISTS
Correct Answer: a) NOT LIKE
Explanation: The NOT LIKE operator returns values that do not match a specified pattern in SQL.
Which SQL keyword is used to remove duplicate rows from the result set of a query?
a) DISTINCTb) GROUP BYc) ORDER BYd) HAVING
Correct Answer: a) DISTINCT
Explanation: The DISTINCT keyword removes duplicate rows from the result set of a query, returning only unique rows.
Which SQL function is used to extract a substring from a string?
a) SUBSTRING()b) CONCAT()c) LENGTH()d) TRIM()
Correct Answer: a) SUBSTRING()
Explanation: The SUBSTRING() function extracts a portion of a string based on specified starting and ending positions.
In SQL, which keyword is used to change the values in a table based on a condition?
a) UPDATEb) DELETEc) INSERTd) SELECT
Correct Answer: a) UPDATE
Explanation: The UPDATE command changes the values in an existing row based on the condition specified in the WHERE clause.
Which SQL function returns the current date without the time portion?
a) CURDATE()b) NOW()c) GETDATE()d) DATE()
Correct Answer: a) CURDATE()
Explanation: The CURDATE() function returns the current date without including the time portion in SQL.