MySQL OR
The OR
operator is used to combine two or more conditions in a SQL query. It returns records where at least one of the conditions is true.
Example with Tamil Kings
1. Using OR with Multiple Conditions
SELECT * FROM tamil_kings_auto_increment
WHERE reign_period = '985–1014 CE' OR king_name = 'Karikala Chola';
Code Explanation: This query selects records from the tamil_kings_auto_increment
table where either the reign_period
is '985–1014 CE' or the king_name
is 'Karikala Chola'. At least one of the conditions must be true for the record to be selected.
Best Practices
- Use
OR
when at least one of multiple conditions should be true. - Combine
OR
withAND
carefully, using parentheses to avoid logical errors.
Key Takeaways
- The
OR
operator returns records that satisfy at least one of the specified conditions. - It is useful for queries that require flexibility in filtering criteria.