Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sqlite

$ 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?

like image 682
Brent Ramerth Avatar asked Feb 05 '10 03:02

Brent Ramerth


People also ask

What does SQLite SELECT return?

SQLite SELECT statement is used to fetch the data from a SQLite database table which returns data in the form of a result table. These result tables are also called result sets.

How do you SELECT all the records from a table named person where the value of the column FirstName starts with an A?

With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"? SELECT * FROM Persons WHERE FirstName LIKE 'a%';

Which SQL How do you SELECT all the records from a table name?

SELECT statements An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value';


1 Answers

Sqlite3 Keywords

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

use single quotes.

like image 184
Sky Sanders Avatar answered Oct 13 '22 10:10

Sky Sanders