OR
Example
Section titled “Example”SELECT * FROM CustomersWHERE Country='Germany' OR Country='France';Output
Section titled “Output”| CustomerID | CustomerName | ContactName | Address | City | Country ||------------|--------------|--------------|-----------------|------------|----------|| 1 | Alfreds | Maria Anders | Obere Str. 57 | Berlin | Germany || 2 | Ana Trujillo | Ana Trujillo | Avda Montero 37 | México D.F | France || 3 | Antonio | Antonio Moreno|Mataderos 2312 | Mexico | France |Explanation
Section titled “Explanation”The code returns all records from the Customers table where the country is either Germany or France. This demonstrated the OR logic, which returns a record if one or both of the conditions are true.
Example
Section titled “Example”SELECT *FROM employeesWHERE department = 'Sales'OR department = 'Marketing';Output
Section titled “Output”+-----------+------+|employee_id|department|+-----------+------+|1 |Sales||2 |Marketing|+-----------+------+Explanation
Section titled “Explanation”This SQL query selects all columns from the employees table where the department is either Sales or Marketing. The OR clause is used to select records that fulfill any of the given conditions.
Example
Section titled “Example”SELECT * FROM EmployeesWHERE City = 'London' OR City = 'Paris';Output
Section titled “Output”| EmployeeID | FirstName | LastName | City ||------------|-----------|----------|-------|| 1 | John | Doe | London|| 3 | Jane | Smith | London|| 5 | Pierre | Dubois | Paris |Explanation
Section titled “Explanation”The OR operator is used in the SQL query to filter the records and return only the employees who are located in either ‘London’ or ‘Paris’. In the output, three records are returned: two from ‘London’ and one from ‘Paris’.
Example
Section titled “Example”SELECT employee_nameFROM employeesWHERE employee_department = 'Sales'OR employee_department = 'Marketing';Output
Section titled “Output”EMPLOYEE_NAME-------------John DoAnn SmithSandra Moore... and so forth ...Explanation
Section titled “Explanation”The SQL statement selects the names of employees in either the ‘Sales’ or ‘Marketing’ departments. The ‘OR’ clause ensures that any employee from either of these departments is included in the results.
Example
Section titled “Example”CREATE TABLE Players ( ID INT PRIMARY KEY, Name TEXT, Age INT, Team TEXT);
INSERT INTO Players (ID, Name, Age, Team)VALUES (1, 'David', 30, 'TeamA'), (2, 'John', 28, 'TeamB'), (3, 'Lucas', 32, 'TeamC'), (4, 'Mark', 31, 'TeamA');
SELECT * FROM PlayersWHERE Age = 30 OR Team = 'TeamB';Output
Section titled “Output”ID | Name | Age | Team---|-------|-----|------1 | David | 30 | TeamA2 | John | 28 | TeamBExplanation
Section titled “Explanation”The SELECT statement with the OR clause in the WHERE condition returns records that meet either of the specified conditions. In the example, it returns records where the player’s Age is 30 or the Team is ‘TeamB’.