Why is this error in SQLiteStudio showing up?

1.7k Views Asked by At

I made a table in SQLiteStudio in DDL:

CREATE TABLE "City " 
(
    Name STRING,
    Population INTEGER,
    Country STRING,
    Elevation INTEGER
);

However, when I start doing queries such as this:

Select AVG(Elevation)
From 'City'
Where Country='Germany';

This error will show up:

Error while executing SQL query on database'': no such table:

Is this because I wrote the syntax wrong or a setting in SQLiteStudio?

1

There are 1 best solutions below

1
On

You have two issues with your query. The first is the single quotes. But, you have a space in the name of the table. So, to query it, you might need to use the space:

Select AVG(Elevation)
From "City "
Where Country = 'Germany';

However, that is really, really silly. Just fix the table by removing the quotes when defining it:

CREATE TABLE City (
    Name STRING,
    Population INTEGER,
    Country STRING,
    Elevation INTEGER
);

To keep your life simple, just give columns and tables names that don't need to be quoted. Then, you don't ever need to use quotes when referring to them.