SQL: Selecting, Filtering and Ordering Rows · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.
به انگلیسی

Ask the database a precise question

Computing · Computer Systems · ages 17-18
Name ______________________   Date ____________
  1. A Books row has pages = 240. In SELECT title FROM Books WHERE pages > 200, what does WHERE do with that row?

    • Deletes it from Books because its title is hidden
    • Keeps it because its page count passes the test
    • Sorts it before every book with a lower page count
  2. In SELECT title, author FROM Books, what does SELECT specify?

    • The columns returned in the result
    • The stored rows deleted from Books
    • The order used to sort every author
  3. OR keeps only the rows that pass both sides of the test.

    Circle one:   True   False

  4. returned is 1 for a returned book and 0 for a book still out. It has no NULLs. Which rows pass WHERE NOT (returned = 1)?

    • All books, whether still out or returned
    • Books still out, where returned is 0
    • Books back on the shelf, where returned is 1
  5. borrowed stores 'yes' or 'no', with no NULLs. Which rows pass WHERE pages > 300 AND borrowed = 'yes'?

    • Borrowed books with any page count
    • Books over 300 pages with any loan status
    • Borrowed books with over 300 pages
  6. Books contains only the titles Ash, Beech and Cedar. In SQLite, SELECT title FROM Books ORDER BY title ASC LIMIT 2; returns Ash and Beech. Changing ASC to DESC returns Cedar and Beech.

    Circle one:   True   False

  7. Books has title, author and borrowed_on columns. SELECT book_title FROM Books reports an unknown-column error. What should you check first?

    • The schema, comparing book_title with its column names
    • The filter, adding a date condition before trying again
    • The sort, adding descending order before trying again
  8. borrowed_on stores YYYY-MM-DD dates. Which SQLite query returns only titles borrowed after 2025-06-01, sorted by title?

    • SELECT title FROM Books WHERE borrowed_on < '2025-06-01' ORDER BY title
    • SELECT title FROM Books ORDER BY title WHERE borrowed_on > '2025-06-01'
    • SELECT title FROM Books WHERE borrowed_on > '2025-06-01' ORDER BY title
LightMySky · lightmysky.comW1-mt_lDVVG2AKzs-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Ask the database a precise question W1-mt_lDVVG2AKzs-s1

  1. Keeps it because its page count passes the test · 240 > 200 is true, so WHERE keeps this row in the result. It does not delete or sort stored rows.
  2. The columns returned in the result · SELECT title, author requests those two columns. FROM Books identifies the table.
  3. False · OR passes when at least one side is true. Requiring both sides to be true describes AND.
  4. Books still out, where returned is 0 · For returned = 0, the comparison returned = 1 is false. NOT makes it true, so books still out survive.
  5. Borrowed books with over 300 pages · Both comparisons must be true: pages must exceed 300 and borrowed must equal 'yes'. A book with exactly 300 pages does not pass.
  6. True · Ascending order is Ash, Beech, Cedar. Descending order is Cedar, Beech, Ash. LIMIT 2 keeps the first two rows in each order.
  7. The schema, comparing book_title with its column names · The schema lists title, not book_title. Compare the requested name with the actual columns before changing filters or sorting.
  8. SELECT title FROM Books WHERE borrowed_on > '2025-06-01' ORDER BY title · Use > to exclude the date and keep later dates. WHERE belongs before ORDER BY, which sorts by title.
Worksheet · LightMySky