A SQL primary key can consist of more than one column.
3 SQL Fundamentals Online Quiz Questions
Use this free practice quiz with 20 questions to review 3 SQL Fundamentals, test your knowledge, and prepare for your next test or exam.
What does COUNT(category) count in a SQL query?
- A
It counts every row, including rows where the column is
NULL. - B
It counts only rows where the column is not
NULL. - C
It counts only distinct values in the column.
- D
It counts the number of columns in the table.
In SELECT name, price * 1.10 AS price_with_tax FROM products;, what alias is assigned to the calculated output column?
Complete each statement with the SQL operator that fits. Use to match one of several listed values, and use to test an inclusive range.
A SQL query without ORDER BY guarantees that its rows will appear in insertion order.
- A
True
- B
False
Select all statements that correctly describe these SQL constraints.
- A
NOT NULLrequires a value for the column. - B
UNIQUEprevents duplicate values. - C
CHECKenforces a condition on allowed values. - D
CHECKguarantees that a column has a value.
A query groups rows by category and calculates an average for each group. Which clause filters the resulting groups based on an aggregate condition?
- A
WHEREfilters groups after aggregation. - B
HAVINGfilters individual rows before grouping. - C
HAVINGfilters groups after aggregation. - D
WHEREandHAVINGboth filter only the final sorted results.
Which SQL operator phrase tests whether category has a NULL value?
Select all statements that correctly describe NULL in SQL.
- A
NULLrepresents a missing or unknown value. - B
NULLis not the same as zero. - C
NULLis not the same as an empty string. - D
category = NULLis the recommended way to test for a missing category.
In an ORDER BY clause, use to sort from lower to higher and to sort from higher to lower.
In databases that support it, what does LIMIT 5 do when added to a query?
- A
It specifies which columns are returned.
- B
It filters rows based on a condition.
- C
It restricts the number of rows returned.
- D
It groups rows before calculating aggregates.
Write a SQL query that returns each category's product count and average price using only in-stock products, keeps only categories with at least two such products, and sorts the results by average price from highest to lowest.
SQL syntax and available data types can vary slightly among database systems.
- A
True
- B
False
What does SELECT * FROM products; request?
- A
It returns only the first column in the table.
- B
It requests all columns from the table.
- C
It returns only columns with no
NULLvalues. - D
It counts the rows in the table.
A products table must reject any row with a negative price while allowing multiple products to have the same price. Which constraint best enforces this rule?
- A
Use UNIQUE on price.
- B
Use CHECK (price >= 0) on price.
- C
Use DEFAULT 0 on price.
- D
Use NOT NULL on price.
A table has 12 rows, and category is NULL in 3 of them. Which statement correctly describes the results of COUNT(*) and COUNT(category)?
- A
COUNT(category)counts every row, including rows where category is NULL. - B
COUNT(*)counts every row, whileCOUNT(category)excludes rows where category is NULL. - C
Both expressions count only rows where category is not NULL.
- D
COUNT(*)counts only rows where every column is non-NULL.
In SELECT price * 1.10 ___ price_with_tax FROM products;, which SQL keyword belongs in the blank to name the expression result price_with_tax?
You need a query to return products priced below 25 that also have at least one item in stock. Which condition correctly filters individual product rows?
- A
Use
WHERE price < 25 OR in_stock > 0. - B
Use
HAVING price < 25 AND in_stock > 0. - C
Use
WHERE price < 25 AND in_stock > 0. - D
Use
GROUP BY price < 25 AND in_stock > 0.
A query selects category and COUNT(*) to report a product count for each category. Which GROUP BY clause matches that goal?
- A
Add
GROUP BY product_id. - B
Add
GROUP BY category. - C
Add
GROUP BY COUNT(*). - D
No GROUP BY clause is needed to calculate a count per category.
A query groups products by category and calculates COUNT(*). Which SQL clause should it use to keep only categories whose count is at least 2?