Brainlag
  1. Library
  2. Debugging
  3. SQL

no such tableWhat is "no such table"?

SQLite stops with "no such table" when a query names a table the database does not have. Usually a typo, a missing s, or a table never created.

SQL5 min

What SQLite is telling you

Output
no such table: song

SQLite looked for a table called song and the database has nothing by that name. It checks every table name before it runs anything, so not a single row comes back.

The usual reasons:

  • Singular or plural. The table is songs, you wrote song. Most databases name tables in the plural, but not all.
  • A typo or a different word. player for players, user for users, order for orders.
  • The table was never made. A CREATE TABLE that failed, or one that runs further down the script.

How to find it

The message names the table it could not find, after the colon. Compare it letter by letter with the real names. To see the real names, run SELECT name FROM sqlite_master WHERE type = 'table'; or look at the tables listed above the editor. If you created the table yourself, check that its CREATE TABLE ran before the query, with no error of its own.

Run it: one letter short

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, year
FROM song
WHERE year >= 2023;

The listener list that will not load

This should list the username and age of every listener from the UK. It stops with "no such table". Fix it.

exercise_1.sql to run
SELECT username, age
FROM listener
WHERE country = 'UK';

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.