SQLite Forum

trying to select one column from one table
Login

trying to select one column from one table

(1) By nsaunders on 2020-11-18 10:38:44 [source]

I imported data from CSV:

nicholas@mordor:~/powershell$ nicholas@mordor:~/powershell$ sqlite3 med SQLite version 3.31.1 2020-01-27 19:55:54 Enter ".help" for usage hints. sqlite> sqlite> .schema CREATE TABLE lab( "Date"",""Region"",""New_Tests"",""Total_Tests"",""Positivity"",""Turn_Around" TEXT ); sqlite> sqlite> select * from lab limit 3; 2020-01-23,"BC",2,2,0,32 2020-01-23,"Fraser",0,0,0,0 2020-01-23,"Interior",0,0,0,0 sqlite> sqlite> select "Date" from lab limit 3; Date Date Date sqlite> sqlite> select "Region" from lab limit 3; Region Region Region sqlite>

perhaps there's some problem with how it was imported? But it seems to "be" in the database fine.

How do I query just a single column, such as "Region", from above.

(2) By Stephan Beal (stephan) on 2020-11-18 10:49:00 in reply to 1 [link] [source]

perhaps there's some problem with how it was imported?

Look very closely at your column definitions:

sqlite> create table foo( "Date"",""Region"",""New_Tests"",""Total_Tests"",""Positivity"",""Turn_Around" );
sqlite> .schema foo
CREATE TABLE foo( "Date"",""Region"",""New_Tests"",""Total_Tests"",""Positivity"",""Turn_Around" );
sqlite> insert into foo values(1);
sqlite> .head on
sqlite> select * from foo;
Date","Region","New_Tests","Total_Tests","Positivity","Turn_Around
1

You've created a table with a single column with a really unusual name.

Use a SINGLE pair of DOUBLE quotes around each column name:

create table lab( "Date", "Region", ... )

for simple names, like the ones you have, no quotes are required (they are required when the column contains spaces or other odd characters).

(3) By David Raymond (dvdraymond) on 2020-11-18 14:17:16 in reply to 1 [link] [source]

As to why it's not giving you an error, it's because double quoted string literals are accepted

Despite using double quotes, since there is no column named "Interior" it says "well, I guess you meant that as a string literal", and returns it as a string literal.

(4) By Keith Medcalf (kmedcalf) on 2020-11-18 16:39:39 in reply to 1 [link] [source]

Get rid of all your useless qotes and try again.