'Use OR operand on BOOL (tinyint(1)) Fields MYSQL

Is it possible to use the OR operand when comparing two boolean values?

Using MYSQL 5+

Ex.

ON DUPLICATE KEY UPDATE
table1.3_InMarket = (table1.3_InMarket OR b.3_InMarket),

I want to set the True value to the field if one exists between the new and the old.

Both those fields are set to tinyint(1) aka Bool.



Solution 1:[1]

You can test the behavior with a simple table.

drop table test;
create table test (
  n integer not null,
  tf boolean not null default false,
  primary key (n)
);
-- Starts false, set to true.
insert into test values (1, false);
insert into test values (1, false) on duplicate key update tf = (tf or true);
-- Starts false, does not set to true.
insert into test values (2, false);
insert into test values (2, false) on duplicate key update tf = (tf or false);
-- Starts true, set to true.
insert into test values (3, true);
insert into test values (3, true) on duplicate key update tf = (tf or true);
-- Starts true, does not set to false.
insert into test values (4, true);
insert into test values (4, true) on duplicate key update tf = (tf or true);

select * from test;

Solution 2:[2]

This is worth checking so that you better understand it as a developer, but this should be perfectly possible.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Sherrill 'Cat Recall'
Solution 2 usumoio