SQL Fundamentals · Final test · 25 questions
SQL Fundamentals final test: 25 free questions
A free SQL Fundamentals practice test with 25 questions drawn from the whole course. Answer at your pace and read why each option is right or wrong.
-
Q1 / 25
In ROUND(total, 2), why does 2 control the requested decimal places?
- AThe largest argument always controls precision
- BNumeric literals are matched by value rather than by position or order
- CROUND reads arguments from right to left
- DPositional arguments match parameters in their listed order
Show the answer
In positional notation, total supplies the first parameter and 2 supplies the second parameter.
Next → 1 / 25 -
Q2 / 25
If T1 RIGHT OUTER JOIN T2 finds no match in T1 for a row in T2, what is the result?
- AThe row from T2 is excluded from the final result set
- BThe row from T2 is returned with NULL values for all columns of T1
- CThe row from T2 is paired with the last valid row from T1
- DThe query fails due to a foreign key violation
Show the answer
A right outer join guarantees that T2 is preserved, so if there is no match in T1, the row from T2 is still returned with NULLs for T1's columns.
Next → 2 / 25 -
Q3 / 25
A table gives `status` a default of `draft`. An INSERT supplies only `sku` and `name`. What row is created?
- AA row with no status column
- BTwo rows, one for each supplied value
- CA complete row whose status is draft
- DNo row, because every column must be named
Show the answer
INSERT always creates a complete row. An omitted column uses its declared default, so this row receives `draft` as its status.
Next → 3 / 25 -
Q4 / 25
Why does the order of the input queries matter when using the EXCEPT operation?
- AEXCEPT keeps first-only rows, so swapping inputs changes which differences remain
- BBecause EXCEPT requires the query with more columns to be written first to determine the output shape
- CBecause EXCEPT removes duplicates only from the first query, leaving duplicates in the second intact
- DEXCEPT sorts using the first key
Show the answer
EXCEPT is directional. It keeps rows in the first result that are absent from the second, so swapping inputs answers the opposite question.
Next → 4 / 25 -
Q5 / 25
What does the token '2030-01-15' prove by itself?
- AIt is a DATE value automatically in every SQL engine without a cast
- BIt is text until a type or context gives it date intent
- CIt is an identifier named 2030-01-15
- DIt includes a time zone
Show the answer
Single quotes establish a string. Date parsing and date-literal forms vary, so code must make the intended type clear.
Next → 5 / 25 -
Q6 / 25
The command ALTER TABLE tracks RENAME COLUMN name TO title runs on the stored tracks. What happens to the six stored titles?
- ANothing changes; the six titles are the same
- BThey are copied into the other columns
- CThey move to a new column and the old one stays
- DThey are cleared, so title starts empty
Show the answer
A rename changes the name of the column and has no effect on the stored data, so the same six titles come back under the heading title.
Next → 6 / 25 -
Q7 / 25
One side of an equality comparison is NULL. What does the comparison return?
- ANULL, meaning unknown
- BA plain false
- CAn error, because null cannot be compared
- DTrue, because both sides are comparable
Show the answer
An ordinary comparison with NULL returns unknown. A WHERE filter keeps only true results, so it drops a row when this comparison is the whole condition.
Next → 7 / 25 -
Q8 / 25
The tracks table holds seven rows, and exactly two of them sit on album 1. Which subquery returns exactly one row, so it is safe in a place that expects a single value?
- ASELECT max(milliseconds) FROM tracks
- BSELECT name, milliseconds FROM tracks
- CSELECT milliseconds FROM tracks
- DSELECT milliseconds FROM tracks WHERE album_id = 1
Show the answer
An aggregate such as max reads the whole table and gives back one row with one column, here the length 375418.
Next → 8 / 25 -
Q9 / 25
Why does a CROSS JOIN not require an ON condition?
- ABecause the WHERE clause is strictly required instead of ON
- BBecause it returns every possible row pair and does not filter the pairs
- CBecause it automatically joins on columns that have identical names
- DBecause the database infers the condition from the primary keys
Show the answer
A CROSS JOIN unconditionally creates a Cartesian product, meaning no matching expression is needed because no pairs are excluded.
Next → 9 / 25 -
Q10 / 25
Which window function assigns the numbers 1, 2, 3, and so on to the rows of a partition, guaranteeing a unique number even for tied rows?
- Arank
- Blag
- Cdense_rank
- Drow_number
Show the answer
The row_number function returns the number of the current row within its partition, counting from 1. It always assigns a unique sequential number, breaking ties based on the internal processing order.
Next → 10 / 25 -
Halfway, at your pace
In the app the mock exam is timed and scored like the real thing.
Opens in your browser. Nothing to install.
Start studying -
Q11 / 25
A `line_total` column must always equal `unit_price` multiplied by `quantity` for its own row, even after the row changes. Which definition gives that?
- A`DEFAULT 0`, with the real total written in by hand later
- BA default of price times quantity, applied once at insert time
- CA generated column computed from the price and quantity of its row
- DNo clause at all, leaving the total to the program that inserts
Show the answer
A generated column is computed from other columns of the same row and is computed again when the row changes, which is exactly what the rule asks for.
Next → 11 / 25 -
Q12 / 25
The invoices from the third of January to the end of January are wanted, and the invoice of the first of February has to stay out. Which condition does that?
- Ainvoice_date BETWEEN '2026-01-03' AND '2026-02-01'
- Binvoice_date >= '2026-01-03' AND invoice_date <= '2026-02-01'
- Cinvoice_date > '2026-01-03' AND invoice_date <= '2026-02-01'
- Dinvoice_date >= '2026-01-03' AND invoice_date < '2026-02-01'
Show the answer
A half-open range keeps its first day and stops before the first day of the next month: the first test is greater than or equal to the third of January, and the second is strictly less than the first of February.
Next → 12 / 25 -
Q13 / 25
One UPDATE must set a product's price to 3.49 and its status to live. Which SET clause does both?
- ASET price = 3.49 AND status = 'live'
- BSET (price = 3.49, status = 'live')
- CSET price, status = 3.49, 'live'
- DSET price = 3.49, status = 'live'
Show the answer
UPDATE assigns several columns by writing comma-separated `column = value` assignments after SET.
Next → 13 / 25 -
Q14 / 25
A named step called customer_totals groups invoices and returns customer_id and spent. The main query reads only `FROM customer_totals`, uses WHERE total >= 10, and fails. Why?
- Acustomer_totals returns no column called total
- BThe main query has to repeat the GROUP BY of the step
- CA WITH clause cannot be followed by a WHERE clause
- DA total can be compared inside the step that adds it
Show the answer
The step returns customer_id and spent; the column total stays inside invoices and never reaches the main query.
Next → 14 / 25 -
Q15 / 25
The `customers` table declares `customer_id` as its primary key. A developer then runs `CREATE UNIQUE INDEX customers_id_idx ON customers (customer_id);`. Which rule does the table gain?
- ANo new rule; duplicates were already refused
- BTwo rows may now share a customer_id
- CThe customer_id column may now hold a null
- DOnly the newest rows are checked for duplicates
Show the answer
A primary key already refuses repeated values in its column, so a unique index over that same column states a rule the table was keeping anyway.
Next → 15 / 25 -
Q16 / 25
Query A returns 10 distinct rows, Query B returns 5 distinct rows, and exactly 3 complete rows are shared. How many rows will Query A UNION ALL Query B return?
- A3 rows
- B15 rows
- C12 rows
- D10 rows
Show the answer
UNION ALL retains all duplicates, meaning it simply adds the row counts together (10 + 5 = 15).
Next → 16 / 25 -
Q17 / 25
A department report must total salaries for active employees and return only departments whose resulting total exceeds 5000. Which query structure satisfies both requirements?
- ATest the total in WHERE, group by department, then filter active rows in HAVING
- BFilter active rows in WHERE, group by department, then test the total in HAVING
- CGroup all rows by department, then test active status and the total together in WHERE
- DFilter active rows in HAVING, then calculate each department total in WHERE
Show the answer
The WHERE clause filters individual input rows (active employees) before groups and aggregates are computed. The HAVING clause selects group rows after the groups and aggregates (total salary > 5000) are computed.
Next → 17 / 25 -
Q18 / 25
The team plans to drop `composer` from `songs`. The view `credits` selects `track_id` and `composer`; the view `hits` selects only `track_id` and `title`. Which view definition has to be dealt with as part of this migration?
- ANeither, the database rewrites view text
- Bcredits, because its text names composer
- CBoth, since both read the same table
- Dhits, because it was created first
Show the answer
The list of readers is what decides. Only the text that names the column being removed has to change, and that is credits. Resolve that dependency first: an engine that enforces it will refuse the drop while the view stands.
Next → 18 / 25 -
Q19 / 25
The six track names are For Those About To Rock, Fast As a Shark, Restless and Wild, Princess of the Dawn, Let There Be Rock and Walk On Water. Which pattern keeps exactly one of them?
- A'Fast As _ Shark'
- B'F%'
- C'%s%'
- D'%Rock'
Show the answer
The underscore stands for exactly one character and the rest of the pattern is plain text, so this shape fits Fast As a Shark and no other name in the table.
Next → 19 / 25 -
Q20 / 25
Inside one transaction, track 1 is repriced at 1.09. A savepoint named step_one follows. Track 2 is repriced at 1.09. The next line runs RELEASE SAVEPOINT step_one. Track 3 is repriced at 1.09, and the work is committed. Which prices are 1.09 at the end?
- AOnly track 3 costs 1.09
- BNone of the five tracks costs 1.09
- COnly tracks 1 and 3 cost 1.09
- DTracks 1, 2 and 3 all cost 1.09
Show the answer
Releasing a savepoint frees the position and keeps the work, so the reprice of track 2 stays. Track 3 is repriced after it, and the commit keeps all three at 1.09.
Next → 20 / 25 -
Q21 / 25
A ledger needs four decimal places and exact sums and equality checks. Which type choice expresses that intent?
- AAn integer with no documented scaling rule
- BA character type because digits can be compared reliably as text
- CUse an exact decimal type with enough precision and scale
- DA floating-point type because it stores approximations
Show the answer
An exact decimal design states the needed precision and scale; the exact type name and limits must be checked for the engine.
Next → 21 / 25 -
Q22 / 25
A query filters artists with EXISTS (SELECT 1 FROM albums b WHERE b.artist_id = a.artist_id). For AC/DC the inner query returns three album rows. What is the value of that test?
- ATrue only if the three rows hold equal values
- BFalse, because the test needs exactly one row
- CUnknown, because the inner query selects a constant
- DTrue, because at least one row came back
Show the answer
The test is true when the subquery returns at least one row, so the three album rows of AC/DC make it true.
Next → 22 / 25 -
Q23 / 25
The store wants at most one invoice per customer per day, while a customer may still buy on many days and several customers may buy on the same day. Which rule states that?
- AOne unique index on each of the two columns separately
- BA unique index on customer_id
- CA unique index on customer_id and invoice_date together
- DA unique index on invoice_date
Show the answer
A unique index over the pair refuses a row when the customer and the date both repeat, which is exactly the stated rule.
Next → 23 / 25 -
Q24 / 25
Which structural requirement must two queries meet before PostgreSQL combines them with a UNION?
- AThey must query tables that share an explicitly defined foreign key relationship
- BThe same column count, with compatible data types in each matching position
- CThey must return columns that have the exact same names in both queries
- DThey must both contain a WHERE clause to filter the results before combining
Show the answer
PostgreSQL needs the same number of columns and compatible types at each matching position. Keeping both lined up also makes the query portable.
Next → 24 / 25 -
Q25 / 25
A table records sales with a year, a region, and an amount. You need to group the sales to find the total amount per region within each year. Which GROUP BY clause forms groups at this intended grain?
- AGROUP BY year, which merges all regions within each year
- BGROUP BY region, which merges all years within each region
- CGROUP BY amount, which groups equal sales values together
- DGROUP BY year, region
Show the answer
To group rows by multiple columns (per region within each year), you list all those columns in the GROUP BY clause. This groups together rows that have the same values in all the listed columns.
Next → 25 / 25 -
That’s the whole mock exam
Every question you miss comes back exactly when you’re about to forget it.
Back to the courseOpens in your browser. Nothing to install.
Start studying
How to use this mock exam
Sit all 25 questions in one go: the mix covers every domain in the same proportion as the exam, so a low score points at the domain you skipped rather than at bad luck.
Read the explanation under every question, including the ones you got right: the reason an option is wrong is usually the thing being tested.
Then retake it in the app, where the mock exam is timed and scored and the questions you miss come back on a schedule.
The whole course, on your computer and your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.
Opens in your browser. Nothing to install.
Start studying“This app is the ‘One Lake’ for preparing the certification exams. Really worth it.”
