SQL OR Keyword
The OR
operator in SQL combines multiple conditions within a WHERE
clause. It selects rows where at least one of the conditions is true.
OR: Definition and Usage
The OR
operator acts as a logical "or"—it means "this condition *or* that condition (or both) must be true". If one or more of the conditions connected by OR
are true, the entire expression evaluates to true, and the corresponding row is included in the query results. Only if *all* conditions linked by `OR` are false will the row be excluded.
Syntax
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
Example
Selecting Customers from Multiple Cities
This query retrieves all customers from either Berlin or München. (This assumes a 'Customers' table exists with a 'City' column.)
Syntax
SELECT * FROM Customers
WHERE City = 'Berlin' OR City = 'München';
Output
(All rows from the Customers table where City is 'Berlin' or 'München' will be returned.)