Test your knowledge of basic SQL commands, such as SELECT, WHERE, JOIN, UPDATE, and more. This quiz covers key SQL concepts, syntax, and common use cases for effective database querying and management.
Which SQL command is used to retrieve specific columns from a table named Employees, such as only the 'name' and 'salary' columns?
Explanation: The SELECT statement is correctly used for retrieving specific columns from a table. FIND, EXTRACT, and SHOW are not valid SQL commands in this context. While they may sound similar or hint at data retrieval, only SELECT follows SQL syntax and semantics.
If you want to get all products with a price greater than 50, which SQL clause should you use to specify this condition?
Explanation: The WHERE clause is used to filter rows based on the specified condition. ORDER BY determines the sorting, not filtering. HAVING is for filtering groups, not individual rows. FILTER BY is not standard SQL syntax.
Which SQL keyword allows you to temporarily rename a column in your result set, such as displaying 'first_name' as 'Name'?
Explanation: The AS keyword is used as an alias for columns or tables to rename them in the query output. LIKE is for pattern matching, IN is used for specifying multiple criteria, and IS is used for comparisons like IS NULL.
How would you combine rows from two tables, for example 'Customers' and 'Orders', to view related information?
Explanation: JOIN is the correct SQL command for combining rows from two or more tables based on a related column. MERGE is not standard in basic SQL for table combination, APPEND is not valid SQL syntax, and LINK is a non-SQL term.
If you want to select users whose age is 18 or 21, which SQL clause helps list multiple possible values in a condition?
Explanation: The IN clause is used to specify multiple possible values in a WHERE condition. CASE is for conditional outputs, BETWEEN is for range queries, and LIKE is for pattern matching, not multiple explicit values.
Which SQL operator should be used to find all usernames that begin with 'admin'?
Explanation: LIKE operator is used in SQL for pattern matching in string comparisons. BEGIN, MATCHES, and STARTS are not valid SQL keywords for this purpose. LIKE allows the use of wildcards such as '%' for flexible searches.
Which SQL command limits the number of rows returned in a query to, for example, only 10 results?
Explanation: LIMIT is the standard SQL clause for restricting the number of records returned, especially in many modern databases. FETCH and TOP can be used in some systems but are less standardized, and ROWNUM is specific to certain database engines.
Which SQL condition should you use to retrieve all rows where the 'email' column is missing a value?
Explanation: IS NULL checks for missing or undefined values in SQL. EQUALS NULL and LIKE NULL are incorrect syntaxes, and IS EMPTY is not standard in SQL for checking null values.
What SQL command updates a table named 'Inventory' to set the 'stock' column to 100 for all rows?
Explanation: UPDATE is used to modify existing data in a table. CHANGE, ALTER (when used alone), and MODIFY are not used in this context in SQL syntax. ALTER is for schema changes, not row updates.
How do you group records in a table by a specific column, such as 'country', to aggregate data like total sales for each country?
Explanation: GROUP BY is designed for grouping rows based on a specific column before applying aggregate functions. ORDER BY merely sorts results, while COLLECT BY and COMBINE BY are not valid SQL commands.
Which SQL statement correctly removes all rows from the 'Logs' table where 'status' equals 'inactive'?
Explanation: DELETE FROM with a WHERE clause is the proper SQL statement for deleting specific rows. REMOVE and ERASE are not SQL commands. DROP deletes the table structure itself, not just the rows.
If you have made changes in a transaction and want to undo them, which SQL command should be used?
Explanation: ROLLBACK undoes all changes made in the current transaction. UNDO, CANCEL, and REVERSE are not standard SQL commands for this purpose, even though their names imply some sort of reversal.
Which SQL function would you use to calculate the average of the 'score' column in a 'Games' table?
Explanation: AVG stands for average and is the correct aggregate function for this calculation. SUM returns the total, COUNT counts the rows, and MIN finds the smallest value, none of which produce the average.
How do you write a SQL statement to list products from the 'Products' table in descending order of their 'price'?
Explanation: ORDER BY with the DESC keyword lists the results in descending order. ORDER price DOWN and SORT BY price DESCEND are not valid syntaxes. GROUP BY is used for aggregation, not for sorting.
Which SQL statement is used to add a column called 'birthdate' to an existing table named 'Employees'?
Explanation: ALTER TABLE with the ADD clause is the correct SQL way to add new columns to an existing table. UPDATE is for modifying data, not structure, and neither MODIFY nor CHANGE are valid commands in this context.
Which SQL construct would you use to return different results in a SELECT query based on a column's value, such as labeling grades as 'pass' or 'fail'?
Explanation: CASE allows you to implement conditional logic in SQL queries to return different values based on certain conditions. SWITCH and IF are not supported keywords in SQL for this scenario, and WHEN is part of the CASE expression rather than being a standalone keyword.