开发者

SQLite SELECT col WHERE col=0; changes results

How could this be happening?

sqlite> select read, text from message;
1|No just got off the train
1|yadayada
1|Beautiful
1|<3
1|DONE <3
0|Hey

sqlite> select read, text from message where read=0;
0|
0|Ooo very cool
0|Donors choose?
0|No prize for the computer reading program / model/master class
0|Hey

I am truncating the very long results from each SQL query. These are the last few results from each. As far as I am aware, there is only one record with column read=0, but when I add the where clause, suddenly all the records return with that value. To confuse 开发者_开发知识库things further, the results are different, or at least in a different order, the output is too long for me to be sure.

Thank you very much for your time and help.


You're not providing an "order by" clause in either SQL statement, so the results are being returned to you in the default order - which is probably by their primary key (if one exists) or by the order they were inserted into the table.

The provided truncation from your first query is most likely the last 6 records in that table. The provided truncation from your second query is most likely the last 6 records in that table WHERE read = 0.

In summary, just because you only see 1 record where read = 0 in the 6 rows you provided from your first query doesn't mean there is only 1. It just means there was only 1 in the last 6 rows. If you wanted to see all the "read = 1" rows first and then all the "read = 0" rows last, trying adding an "order by" clause.

sqlite> select read, text from message order by read, text;

sqlite> select read, text from message where read=0 order by text;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜