Brainlag
  1. Library
  2. Debugging
  3. SQL

no such columnWhat is "no such column"?

SQLite stops with "no such column" when a query uses a column name the table does not have: a guess, a typo, a text value without quotes, or an alias used too early.

SQL5 min

What SQLite is telling you

Output
no such column: length

The query asked for a column called length, and none of the tables in it has one. Nothing runs. The four usual reasons:

  • A guessed name. The column is seconds, you guessed length or duration.
  • Text without quotes. WHERE country = UK reads UK as a column name. Text values need single quotes: 'UK'. Double quotes, "UK", also mean a name in SQL, so stick to single quotes for text.
  • An alias used in WHERE. SELECT seconds / 60 AS minutes ... WHERE minutes > 3 fails, because WHERE runs before SELECT has named anything.
  • The wrong table. After a join, a.title fails if title lives in the other table.

How to find it

Read the name after the colon. Then check where it is used: if it is a value you meant to compare with, add quotes; if it is a real column name, look at the table's columns (the list above the editor, or PRAGMA table_info(songs);) and use the real spelling. If it is a name you made with AS, repeat the expression in WHERE instead.

Run it: a column that is not there

Press Run and read the error from the bottom up.

Tables artists, songs, listeners, plays
artists 8 rows, 4 columns
idnamecountrygenre
1Nova LaneUKpop
2The TidewaterUSindie
3Kaito MoriJPelectronic
4Amara OseiGHafrobeats
5Lumen ChoirSEpop
6Rust & VelvetUKrock
7Pixel HeartsKRpop
8Juno BayAUindie
songs 30 rows, 5 columns
idtitleartist_idsecondsyear
1Neon Rain61782022
2Slow Motion11582025
3Paper Planes22332023
4Static12692020
5Golden Hour11622022
6Night Bus71572020
7Echoes22812022
8Sugar Rush12842019
9Low Tide42892019
10Glass House71522020
11Satellite12822025
12Wildfire32142022

First 12 of 30 rows. Query the table to see the rest.

listeners 10 rows, 4 columns
idusernameagecountry
1maya_k15UK
2devraj17IN
3lucia.p16ES
4tom_h14UK
5ana.s18BR
6kenji16JP
7zoe_r15US
8femi17NG
9liv13SE
10oscar.b16NULL
plays 70 rows, 5 columns
idlistener_idsong_iddayskipped
110162026-09-010
2832026-09-010
35162026-09-010
4222026-09-010
55212026-09-010
65232026-09-020
7612026-09-020
8662026-09-020
9822026-09-021
10552026-09-020
117132026-09-020
12262026-09-030

First 12 of 70 rows. Query the table to see the rest.

query.sql to run
SELECT title, length
FROM songs
ORDER BY length DESC;

Listeners from Spain go missing

This should list the username and age of every listener from Spain (ES). It stops with "no such column". Fix it.

exercise_1.sql to run
SELECT username, age
FROM listeners
WHERE country = ES;

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.