[{"id":"sqlserveradvanced-001","courseId":"sql-server-advanced","domain":"querying","topic":"Logical processing order of SELECT","prompt":"A query uses WHERE, GROUP BY, HAVING, SELECT and ORDER BY. Put these clauses in the order the query processor logically binds them.","hint":"Think about which stages must finish before later stages can use their results.","explain":"A query narrows its data in stages: some work on single rows, others on collections built from those rows, and some arrange the output. A name defined in one stage is usable only by stages that run after it.","source":"https://learn.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql","interaction":{"type":"sort","items":[{"text":"WHERE","why":"Filters the individual rows produced by FROM and ON, before any grouping happens."},{"text":"GROUP BY","why":"Builds groups from the rows that passed the filter above."},{"text":"HAVING","why":"Filters the groups, so it can only run once they exist."},{"text":"SELECT","why":"Computes the output columns and their aliases after grouping and filtering are finished."},{"text":"ORDER BY","why":"Arranges the result after the select list is set, so it may use the aliases defined there."}]},"options":[],"answer":"o:abcde","explanation":"Logical processing binds FROM, then WHERE, GROUP BY and HAVING, then the SELECT list, so aliases defined in the SELECT list can be referenced only by later clauses such as ORDER BY.","concept":"Logical processing binds FROM, then WHERE, GROUP BY and HAVING, then the SELECT list, so aliases defined in the SELECT list can be referenced only by later clauses such as ORDER BY.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["A select-list alias can't be used in WHERE, but ORDER BY can use it.","The logical order isn't guaranteed to match the physical execution plan."]},{"id":"sqlserveradvanced-002","courseId":"sql-server-advanced","domain":"querying","topic":"NOT IN with NULL values","prompt":"A query keeps orders whose customer is not on the VIP list. One VIP row has a NULL customer_id. Comparing that NULL with each order's customer_id gives what result?","hint":"Consider what a comparison that involves a missing value evaluates to.","explain":"SQL conditions can have more than two outcomes. A WHERE clause keeps a row only when its condition is definitely satisfied. Consider how a missing value inside a candidate list affects a membership test.","source":"https://learn.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql","interaction":{"type":"single"},"options":[{"id":"a","text":"UNKNOWN, a result that is neither true nor false","why":"A NULL compared with IN or NOT IN returns UNKNOWN, which is neither TRUE nor FALSE."},{"id":"b","text":"FALSE, so the NULL is skipped and the test ignores it","whyNot":"The NULL isn't skipped. Its comparison returns UNKNOWN, not FALSE."},{"id":"c","text":"TRUE, because NULL matches every value in a NOT IN list","whyNot":"NULL matches nothing, and a NOT IN test with a NULL present can never come out TRUE."},{"id":"d","text":"An error, since NOT IN rejects any NULL in its list","whyNot":"The query runs normally; the NULL just makes that comparison unknown."}],"answer":"a","explanation":"Any null values returned by the subquery that are compared with IN or NOT IN return UNKNOWN, which can produce unexpected results.","concept":"Any null values returned by the subquery that are compared with IN or NOT IN return UNKNOWN, which can produce unexpected results.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"SELECT id\nFROM orders\nWHERE customer_id NOT IN\n  (SELECT customer_id\n   FROM vip);","takeaways":["NULL values in a NOT IN subquery can produce unexpected results.","Comparisons with null values under IN or NOT IN return UNKNOWN."]},{"id":"sqlserveradvanced-003","courseId":"sql-server-advanced","domain":"querying","topic":"MERGE upserts","prompt":"A MERGE statement joins a target table to a source table with an ON condition. Which TWO statements about its clauses are correct?","hint":"Think about how many source rows can pair with one target row, and how many clauses of each kind are allowed.","explain":"A MERGE checks each pairing of its two inputs for a partner, and each outcome gets its own action. Its structure carries limits on how the branches combine and on how often one stored entry can be changed.","source":"https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"If several source rows match one target row, an UPDATE action on that match raises an error.","why":"When UPDATE is the matched action and more than one source row matches a target row, SQL Server returns an error."},{"id":"b","text":"Only one WHEN NOT MATCHED BY TARGET clause is allowed per statement.","why":"The statement can have only one clause of that kind, the one that inserts unmatched source rows."},{"id":"c","text":"Two source rows can both update the same target row, and the last one applied wins.","whyNot":"A MERGE can't update the same row more than once, so a last-one-wins outcome never happens."},{"id":"d","text":"Three WHEN MATCHED clauses are allowed when each has its own AND condition.","whyNot":"At most two WHEN MATCHED clauses are permitted in one statement."},{"id":"e","text":"An extra NOT condition on target columns in the ON clause speeds up the match.","whyNot":"The docs warn against filtering target rows in the ON clause, since that can return unexpected and incorrect results."},{"id":"f","text":"WHEN NOT MATCHED BY SOURCE can set a target column from a source column.","whyNot":"When no source rows are returned, source columns can't be accessed, so that action can fail with error 207."}],"answer":"ab","explanation":"When UPDATE is the matched action and more than one source row matches a target row, SQL Server returns an error; a MERGE also allows only one WHEN NOT MATCHED [BY TARGET] clause.","concept":"When UPDATE is the matched action and more than one source row matches a target row, SQL Server returns an error; a MERGE also allows only one WHEN NOT MATCHED [BY TARGET] clause.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["A MERGE update fails when one target row matches several source rows.","Put only target-to-source matching columns in the ON clause."]},{"id":"sqlserveradvanced-004","courseId":"sql-server-advanced","domain":"querying","topic":"OUTPUT clause capturing changes","prompt":"In an UPDATE that has an OUTPUT clause, the returned values show the changed rows as they stand after the statement completes but before any AFTER trigger on the table runs.","hint":"Think about the moment the returned values are captured relative to follow-up logic on the table.","explain":"A data change can set off follow-up logic on the table it modifies, so the moment a result is read matters. Consider where the returned values sit relative to the change and to that follow-up logic.","source":"https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"OUTPUT reflects the data after the statement completes, before triggers are executed."},{"id":"b","text":"False","whyNot":"OUTPUT doesn't see changes made by triggers that run afterwards; those aren't reflected in its columns."}],"answer":"a","explanation":"Columns returned from OUTPUT reflect the data as it's after the INSERT, UPDATE, or DELETE statement completes, but before triggers are executed.","concept":"Columns returned from OUTPUT reflect the data as it's after the INSERT, UPDATE, or DELETE statement completes, but before triggers are executed.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","takeaways":["OUTPUT values are captured before AFTER triggers run.","Variables modified in an UPDATE return their pre-statement values through OUTPUT."]},{"id":"sqlserveradvanced-005","courseId":"sql-server-advanced","domain":"querying","topic":"Default RANGE window frame","prompt":"A teammate writes MAX(price) OVER (PARTITION BY store_id ORDER BY sold_on) and leaves out any frame clause. Which default window frame does SQL Server apply?","hint":"Think about how far back the frame reaches when the query leaves it unspecified.","explain":"A window function that depends on order reads a frame: the set of data it sees for each output. When the query omits one, the engine supplies a default that counts positions or ordering values.","source":"https://learn.microsoft.com/en-us/sql/t-sql/queries/select-over-clause-transact-sql","interaction":{"type":"single"},"options":[{"id":"a","text":"RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW","why":"With an ORDER BY and no frame, MIN and MAX use a range from the partition start to the current element."},{"id":"b","text":"ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW","whyNot":"Close, but the default is a RANGE frame, not a ROWS frame."},{"id":"c","text":"RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING","whyNot":"That spans the whole partition; the whole partition is the window only when there is no ORDER BY."},{"id":"d","text":"ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING","whyNot":"That looks forward from the current element; SQL Server doesn't default to a forward-looking frame."}],"answer":"a","explanation":"For functions such as MIN or MAX with an ORDER BY but no ROWS or RANGE specification, the default window frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.","concept":"For functions such as MIN or MAX with an ORDER BY but no ROWS or RANGE specification, the default window frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.","rev":1,"updatedAt":"2026-10-27","kind":"scenario","code":"SELECT store_id,\n  MAX(price) OVER (\n    PARTITION BY store_id\n    ORDER BY sold_on\n  ) AS top_price\nFROM sales;","takeaways":["An ORDER BY without a frame makes MIN and MAX use a running range.","Without an ORDER BY, the window covers the whole partition."]}]