Quiz: Prove your SQL Skills!
Are you team SQL? Or noSQL?
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! 👇
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';
.
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))
.
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.
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:
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.
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.
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
.
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.