This MariaDB tutorial explains how to use the MariaDB OR condition with syntax and examples.
The MariaDB OR condition is used to test two or more conditions where records are returned when any one of the conditions are met. The OR condition can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the OR condition in MariaDB is:
Any of the conditions that must be met for the records to be selected.
Let's look at how to use the OR condition in the SELECT statement in MariaDB.
For example:
This MariaDB OR condition example return all sites that have a site_name of 'mySite.com' or a site_id that is equal to 2. Because the * is used in the SELECT statement, all fields from the sites table would appear in the result set.
Let's look at how to use the OR condition to test for three conditions in the SELECT statement in MariaDB.
For example:
This OR condition example would return all site_id and site_name values where the site_name is either 'mySite.com' or 'AODBA.com' or the site_id is equal to 2.
Let's look at how to use the OR condition in the INSERT statement in MariaDB.
For example:
This MariaDB OR example would insert into the contacts table, all site_id and site_name records from the sites table that have a site_name of 'AODBA.com' or the site_id is less than 1000.
Let's look at how to use the OR condition in the UPDATE statement in MariaDB.
For example:
This OR condition example would update all site_name values in the sites table to 'AODBA.com' where the site_id is equal to 10 or the site_name is 'data.com'.
Finally, let's look at how to use the OR condition in the DELETE statement in MariaDB.
For example:
This MariaDB OR example would delete all records from the sites table where the site_name is 'AODBA.com' or the site_id is equal to 65.