You have a collection of blog posts stored in a database. Each post has a title and date. You want to render a list of post titles sorted by date descending.
Which SQL query will return the correct ordered list of titles?
Think about how to order results from newest to oldest.
Option A correctly orders posts by date descending, showing newest first. Option A orders ascending (oldest first). Option A has invalid syntax. Option A uses a non-standard keyword.
You want to render only published articles from a collection where each article has a status field. Which SQL WHERE clause filters published articles?
Use the standard equality operator in SQL.
Option A uses correct SQL syntax for equality. Option A uses double equals which is invalid in SQL. Option A uses LIKE which is for pattern matching, not exact match. Option A is invalid syntax.
Identify the option that fixes the syntax error in this query:
SELECT title, date FROM posts WHERE status = 'published' ORDER date DESC;
Check the correct keyword for ordering results in SQL.
Option D uses the correct 'ORDER BY' syntax. Option D uses invalid 'SORT BY'. Option D misses 'BY' keyword. Option D has wrong order of keywords.
You want to render a large collection of products but only show 20 per page. Which SQL clause helps limit the number of rows returned for pagination?
Consider the standard SQL clause for limiting rows.
Option C is standard SQL for limiting rows. Option C is specific to some SQL dialects like SQL Server. Option C is valid in some dialects but less common. Option C is invalid.
You run this query to render published posts but get no results:
SELECT * FROM posts WHERE status = 'publish';
What is the most likely reason?
Check the exact values stored in the status field.
Option B is correct because the status value is likely 'published' not 'publish'. Option B would cause an error, not empty result. Option B is optional and does not affect results. Option B is valid syntax.
