Test your knowledge of SQL fundamentals, functions, joins, optimization, and advanced concepts with this beginner-friendly quiz designed for aspiring data engineers. Strengthen your SQL skills with real-world questions suitable for interview preparation.
Which of the following best describes a primary key in SQL?
Explanation: A primary key uniquely identifies each row within a table and ensures no duplicate values are present in that column. Deleting tables or updating rules are unrelated to primary keys. Grouping data is done using GROUP BY and not by primary keys.
If you want to retrieve all rows and columns from a table named 'employees', which SQL statement should you use?
Explanation: The correct SQL query is 'SELECT * FROM employees;'. The syntax uses SELECT followed by an asterisk to choose all columns, and FROM to specify the table name. The other options are incorrect SQL syntax or commands that do not exist in SQL.
What is the main difference between the WHERE and HAVING clauses in SQL?
Explanation: WHERE is used to filter rows before grouping occurs, while HAVING is used to filter data after GROUP BY has been applied. The other options describe unrelated tasks such as sorting, merging, or incorrectly defining the clauses.
Which SQL function would you use to combine two strings into one, such as joining first and last names?
Explanation: The CONCAT() function is used to join two or more strings together in SQL, making it ideal for creating full names from separate columns. DIVIDE() and FORMAT() are unrelated to string joining, while MATCH() is not used for concatenating values.
If a column has NULL values, which function can you use in SQL to replace them with a default value?
Explanation: COALESCE() is designed to return the first non-NULL value in a list, making it ideal to replace NULLs with defaults. UCASE() is for converting text to uppercase, DISTINCT() selects unique values, and INCLUDE() is not a SQL function.
Which type of join returns only the rows where there is a match in both joined tables?
Explanation: INNER JOIN retrieves rows where there is a matching value in both tables, ensuring only common records appear. FULL OUTER JOIN includes all records with or without matches, RIGHT JOIN shows all from the right table, and CROSS JOIN forms combinations regardless of matches.
Which aggregate function in SQL returns the highest value from a specified column?
Explanation: MAX() returns the largest value from the column specified. MIN() returns the lowest, SUM() adds up all numbers, and AVG() returns the average. Only MAX() provides the highest numerical or alphabetical value.
To find all usernames starting with 'A', which SQL clause would you most commonly use?
Explanation: The LIKE clause is used for pattern matching, and 'A%' means any string starting with 'A'. GROUP BY is used for aggregation, COUNT() returns counts, and SORT BY is used for ordering, not matching patterns.
Which function helps extract the year value from a date column in SQL?
Explanation: YEAR() extracts the year part from a date. ROUND() is for numerical rounding, INDEX() deals with database structure, and RANK() is used for ranking rows. None except YEAR() is related to dates.
If you want to check if a value exists within a set of multiple possible values, which operator should you use in SQL?
Explanation: 'IN' checks if a value matches any value within a list. 'BETWEEN' checks ranges, 'JOIN' is for combining tables, and 'UPPER' is a string function for capitalization, not comparisons.
How do SQL indexes generally improve database performance?
Explanation: Indexes create a quick lookup reference, enabling databases to search for rows much faster than scanning all data. They do not increase the column count, create backups, or encrypt data; those are different database features.
What is a view in SQL?
Explanation: A view is a stored query that behaves like a table for reading data but doesn’t store data itself. A backup is a copy of a table's actual data, not a view. Rows with permissions and primary keys are unrelated concepts.
Which clause is used in SQL to arrange identical data into groups?
Explanation: GROUP BY groups rows sharing the same values in specified columns, often used with aggregate functions. ORDER BY sorts data, WHERE filters data, and FORMAT BY is not a SQL clause.
What is the main purpose of a transaction in SQL databases?
Explanation: Transactions guarantee all included operations succeed or fail together, ensuring data consistency. Sorting data, adding keys, and backups are unrelated tasks not covered by transactions.
What is the primary goal of normalization in SQL databases?
Explanation: Normalization is designed to minimize repetition and ensure data is organized efficiently, supporting integrity. Increasing tables without structure, automatic reports, and transaction speed are not direct goals of normalization.