First Steps Into Practising SQL With Open Data

Made-up tables are great for learning the basics, but real data is more interesting. Many governments and organisations publish open data that anyone can download and use. This guide shows how to turn a public data set into SQL practice.

What open data is

Open data is information published so that anyone can use it, usually under a licence that allows reuse with credit. Examples include public transport timetables, library statistics, weather records and lists of public facilities.

Where to find it

Look for files in CSV format (comma-separated values). They are easy to load into a database.

Step 1: pick a small, friendly data set

Choose something you find interesting and that has a few thousand rows or fewer. A list of public libraries, parks or bus stops works well. Read the description and licence on the portal page.

Step 2: load the CSV into SQLite

The sqlite3 command-line shell can import a CSV directly:

sqlite3 practice.db
sqlite> .mode csv
sqlite> .import parks.csv parks
sqlite> .mode column
sqlite> SELECT COUNT(*) FROM parks;

The first line of the CSV usually becomes the column names. DB Browser for SQLite also has an "Import table from CSV file" option if you prefer a graphical tool.

Step 3: look before you query

SELECT * FROM parks LIMIT 5;

Check the column names, whether numbers look like numbers, and whether some cells are empty. Real data is often messy.

Step 4: ask your own questions

Write a list of questions first, then turn each into SQL. For a parks data set:

QuestionPossible SQL idea
How many parks are there?COUNT(*)
Which area has the most parks?GROUP BY area ORDER BY COUNT(*) DESC
Which parks have a playground?WHERE on a facilities column
Which parks have no listed area?WHERE area IS NULL OR area = ''

Step 5: clean up a little

You may find extra spaces, inconsistent spellings or numbers stored as text. Practising fixes like TRIM() and UPDATE on your own copy is great experience. Never change the original file; keep it as a backup.

Step 6: credit the source

Most open data licences ask you to say where the data came from. If you share your project, include the portal name, the data set title and the licence in your README.

Things to watch

Why this is worth doing

Answering a real question with your own SQL is one of the most satisfying moments in learning databases, and it makes a great portfolio project. Our beginner course on SELECT queries covers the query skills you will need.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.