OR

Description

Logical OR,||. When both operands are non-NULL, the result is true if any operand is nonzero, and false otherwise. With a NULL operand, the result is true if the other operand is nonzero, and NULL otherwise. If both operands are NULL, the result is NULL.

Syntax

1. > SELECT column_1 OR column_2 FROM table_name;

Examples

1. mysql> select 1 or 1;
2. +--------+
3. | 1 or 1 |
4. +--------+
5. | true   |
6. +--------+
7. 1 row in set (0.01 sec)

9. mysql> select 1 or 0;
10. +--------+
11. | 1 or 0 |
12. +--------+
13. | true   |
14. +--------+
15. 1 row in set (0.00 sec)

17. mysql> select 0 or 0;
18. +--------+
19. | 0 or 0 |
20. +--------+
21. | false  |
22. +--------+
23. 1 row in set (0.01 sec)

25. mysql> select 0 or null;
26. +-----------+
27. | 0 or null |
28. +-----------+
29. | NULL      |
30. +-----------+
31. 1 row in set (0.00 sec)

33. mysql> select 1 or null;
34. +-----------+
35. | 1 or null |
36. +-----------+
37. | true      |
38. +-----------+
39. 1 row in set (0.00 sec)
1. create table t1 (a boolean,b bool);
2. insert into t1 values (0,1),(true,false),(true,1),(0,false),(NULL,NULL);

4. mysql> select a or b from t1;
5. +--------+
6. | a or b |
7. +--------+
8. | true   |
9. | true   |
10. | true   |
11. | false  |
12. | NULL   |
13. +--------+
14. 5 rows in set (0.00 sec)