0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 3
    Don't use single quotes around the table name in your query. – sgeddes Feb 22 '16 at 00:02
  • 1
    Check the name of the table you created (City) and make sure it doesn't have a space at the end as specified in your CREATE TABLE statement. – randyh22 Feb 22 '16 at 00:06

1 Answers1

0

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786