>_ IzzyLab

Hands-on task

This task is step 3 of the course “SQL with SQLite”

SQLite: unique cities (DISTINCT)

easy~3 min

The database /root/shop.db has a table visits(id, city) where cities repeat. Output the list of unique cities (no duplicates) and write it to /root/out.txt (one city per line).

What you'll practise:
  • sqlite3
  • distinct
  • unique values
  • deduplication

Topic breakdown

DISTINCT removes duplicates from the result, keeping only unique combinations of all selected columns at once. The key nuance: uniqueness is measured over the whole selected row, so an extra column (for example id) will break the collapsing — duplicates will stop merging. It is essentially a special case of GROUP BY on the same columns without aggregates; the order of output rows is not guaranteed.

What's checked

  1. no duplicates in the result
  2. all cities from the table are present

What it looks like