Dan Levy's Avatar DanLevy.net

Quiz: Prove your SQL Skills!

Are you team SQL? Or noSQL?

Quiz: Prove your SQL Skills!

Test your SQL Query Fundamentals

Has using an ORM been making you soft - in the skills dept? Don’t worry, it happens to loads of devs.

Jump right in to prove your SQL Query Fundamentals! 👇

1. 

SQL Basics

Which of the following SQL queries correctly retrieves rows where the name is “John”?

In SQL, single equal sign (=) is used for equality checks in the WHERE clause, not == or ===, which are JavaScript operators.

The correct syntax is SELECT * FROM users WHERE name = 'John';.

2. 

SQL Basics

What does COUNT(column_name) do in SQL?

COUNT(column_name) counts the number of non-NULL values in a specified column. To count all rows, including NULLs, use COUNT(*).

You can also use COALESCE to ensure NULLs default to a non-NULL value. Something like: COUNT(COALESCE(column_name, 0)).

3. 

SQL Joins

What does a LEFT JOIN do in SQL?

A LEFT JOIN returns all rows from the left table and matched rows from the right table, with NULL for unmatched rows in the right table.

4. 

SQL Joins

What does an INNER JOIN do in SQL?

An INNER JOIN returns rows where there is a match in both tables. Unmatched rows are not included in the result set.

5. 

SQL Subqueries

What is a correlated subquery in SQL?

A correlated subquery is evaluated once per row of the outer query. It references columns from the outer query, making it dependent on each row.

6. 

SQL CTEs

What is the purpose of the WITH clause (Common Table Expression) in SQL?

The WITH clause, or Common Table Expression (CTE), is used to define a temporary result set that can be referenced within the main query.

This can help improve readability and maintainability of complex queries.

The syntax is:

WITH cte_name AS (
SELECT column_name
FROM table_name
)
SELECT *
FROM cte_name;

7. 

SQL Basics

What does the IS NULL operator do in SQL?

IS NULL checks if a specified column contains a NULL value. IS NOT NULL checks the opposite.

8. 

SQL Operators

What does the IN operator do in SQL?

The IN operator filters rows to match any values in a specified list, often as an alternative to multiple OR conditions.

While it might return “unique rows” (and often does), it’s not necessarily the primary purpose.

Indexing is not required here, though it’s certainly a best practice to use IN on a column with an index, preferably a UNIQUE index, as it can improve performance.

9. 

SQL Functions

What does the COALESCE function do in SQL?

The COALESCE function returns the first non-NULL value in a specified list, useful for substituting default values when NULLs are encountered.

For example, COALESCE(column_name, 0) would return 0 if column_name is NULL.

10. 

SQL Aggregate Functions

What is the purpose of the GROUP BY clause in SQL?

The GROUP BY clause groups rows that have the same values in specified columns, allowing aggregate functions to be applied on each group.

11. 

SQL Joins

What does a FULL OUTER JOIN do in SQL?

A FULL OUTER JOIN returns all rows from both tables, filling unmatched rows with NULLs for missing values.

This is useful for comparing two tables and finding differences between them.

Quiz Score:

Congrats! Quiz completed.

Edit on GitHubGitHub