How to make a condition with logical OR in SQL (MySQL), so that the sub-conditions would be carried out on an as-needed basis ?
For example:
SELECT * FROM \`mytable\` WHERE (\`a\` || \`b\` || \`c\`)
`a` is FALSE
`b` is TRUE
`c` is FALSE or TRUE
I want to MySQL:
1) get `a` // ok, `a` is FALSE
2) if (`a` IS TRUE) break // no break
3) get `b` // ok, `b` is TRUE
4) if (`b` IS TRUE) break; // ok, break
Logical
ORalready behaves that way.However what is considered evaluation of those expressions is not necessarily what you expect, e.g. database may still need to fetch all rows related to the expression. Specifically, MySQL can’t always use indexes if you use
OR.BTW: You should use
OR, which is a standard SQL syntax.||in ANSI SQL (other databases and ANSI mode in MySQL) concatenates strings.