sqlite SELECT在查询列中与该列同名的值时返回所有记录 [英] sqlite SELECT returns all records when querying a column for a value with the same name as the column
本文介绍了sqlite SELECT在查询列中与该列同名的值时返回所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ 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>
似乎查询将foo"视为对列名称的引用,而不是字符串常量.我如何让这个查询只返回 foo 而不是 bar?除了重命名列之外还有其他选择吗?
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?
推荐答案
sqlite> SELECT * FROM test WHERE foo='foo';
使用单引号.
这篇关于sqlite SELECT在查询列中与该列同名的值时返回所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文