开发者

If I have a sql query with a where clause what happens when there is no operator on `where`?

开发者 https://www.devze.com 2023-03-27 19:34 出处:网络
For example, if I had the following query: select * from msgs as开发者_StackOverflow e left outer join msgs as m on e.id = m.idwhere m.property

For example, if I had the following query:

select * from msgs as开发者_StackOverflow e left outer join msgs as m on e.id = m.id where m.property

what exactly happens in the where part of the query?


If the value of m.property evaluates to true when interpreted as a boolean expression, the row gets selected.

See http://www.sqlite.org/lang_select.html#whereclause

It says

  • If a WHERE clause is specified, the WHERE expression is evaluated for each row in the input data as a boolean expression. All rows for which the WHERE clause expression evaluates to false are excluded from the dataset before continuing.

For boolean expression it says

  • To convert the results of an SQL expression to a boolean value, SQLite first casts the result to a NUMERIC value in the same way as a CAST expression. A NULL or zero value (integer value 0 or real value 0.0) is considered to be false. All other values are considered true. For example, the values NULL, 0.0, 0, 'english' and '0' are all considered to be false. Values 1, 1.0, 0.1, -0.1 and '1english' are considered to be true.

So it should evaluate m.property and cast it to a boolean, and keep the rows for which it is true.

0

精彩评论

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