Mysql where 1 = 0 confusion

In a simple sql book, there is a part of the code mention, if I use where 1 = 0, I can safely add OR conditions, for example:

WHERE
   1=0
   OR name LIKE '%Toledo%'
   OR billaddr LIKE '%Toledo%'
   OR shipaddr LIKE '%Toledo%'

I did not understand why, when I use where 1 = 0, I can safely add the OR instruction

Is it possible to use something like below?

WHERE
   1=1
   OR name LIKE '%Toledo%'
   OR billaddr LIKE '%Toledo%'
   OR shipaddr LIKE '%Toledo%'

I understand what where 1=1is a shortcut to adding an AND operator. I understand, because it where 1 =1will return true. Can I use it for expression Ortoo?
Istill didn't get the part. where 1 = 0
Any explanation would be wonderful.

+4
source share
3 answers

, . AND, , true, 1 = 1. , OR, , false, 1 = 0.

, x ( . .) , x AND false, get false, , x.

, x OR true, true. , x.

, . false OR a OR b OR c a OR b OR c, . true AND a AND b AND c a AND b AND c.

+4

MySQL .

TRUE FALSE, MySQL .

TRUE OR ? OR ? TRUE, MySQL .
FALSE AND ? AND ? FALSE, MySQL .

() , MySQL LIKE, :

SELECT * FROM atable
WHERE
   1=1                         /* <--- this makes the whole OR set always true*/
   OR name LIKE '%Toledo%'     /* therefore the like tests are never done     */
   OR billaddr LIKE '%Toledo%' /*and all rows are returned */
   OR shipaddr LIKE '%Toledo%'

:

SELECT * FROM atable
WHERE
   1=0                          /* false OR ? has an unknown outcome so */
   OR name LIKE '%Toledo%'      /* MySQL has to evaluate the LIKE tests */
   OR billaddr LIKE '%Toledo%'  /*only some rows will be returned*/
   OR shipaddr LIKE '%Toledo%'

AND

+1

Is it possible to use something like below?

WHERE
   1=1
   OR name LIKE '%Toledo%'
   OR billaddr LIKE '%Toledo%'
   OR shipaddr LIKE '%Toledo%'

which will return every row (since it is always true), so no ...

0
source

All Articles