W3. SQL Or Flashcards
Q: What does the SQL OR operator do?
A: It filters records based on multiple conditions, returning records if at least one condition is true.
Q: Write a SQL query to select all customers from Germany or Spain.
SELECT * FROM Customers WHERE Country = 'Germany' OR Country = 'Spain';
Q: What is the syntax for using multiple OR conditions in SQL?
SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 …;
Q: How does the OR operator differ from the AND operator?
A: OR requires at least one condition to be true, while AND requires all conditions to be true.
Q: Write a query to select all customers where the city is “Berlin,” the CustomerName starts with “G,” or the country is “Norway.”
SELECT * FROM Customers WHERE City = 'Berlin' OR CustomerName LIKE 'G%' OR Country = 'Norway';
Q: Can AND and OR operators be combined in the same SQL query?
A: Yes, they can be combined, often using parentheses for correct grouping.
Q: Why are parentheses important when using AND and OR together?
A: They ensure the intended grouping of conditions, so SQL evaluates them in the correct order.
Q: Write a query to select all Spanish customers with names starting with “G” or “R.”
SELECT * FROM Customers WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%');
Q: What can happen if parentheses are omitted in a combined AND/OR query?
A: SQL may misinterpret the grouping, returning unintended results.
Q: Write a query to select customers who are either from Spain and start with “G” or start with “R” regardless of country.
SELECT * FROM Customers WHERE Country = 'Spain' AND CustomerName LIKE 'G%' OR CustomerName LIKE 'R%';