Brent Ramerth
Brent Ramerth

Reputation: 315

sqlite SELECT returns all records when querying a column for a value with the same name as the column

$ sqlite3 test.db
SQLite version 3.6.21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE test(foo text);
sqlite> INSERT INTO test VALUES ("foo");
sqlite> INSERT INTO test VALUES ("bar");
sqlite> SELECT * FROM test WHERE foo="foo";
foo
bar
sqlite>

It seems that the query treats "foo" as a reference to the name of the column, rather than as a string constant. How do I get this query to only return foo, not bar? Are there options besides renaming the column?

Upvotes: 5

Views: 3305

Answers (1)

Sky Sanders
Sky Sanders

Reputation: 37074

Sqlite3 Keywords

sqlite> SELECT * FROM test WHERE foo='foo';

use single quotes.

Upvotes: 10

Related Questions