W3. SQL Or Flashcards

1
Q

Q: What does the SQL OR operator do?

A

A: It filters records based on multiple conditions, returning records if at least one condition is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Write a SQL query to select all customers from Germany or Spain.

A
SELECT * FROM Customers 
WHERE Country = 'Germany' OR Country = 'Spain';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What is the syntax for using multiple OR conditions in SQL?

A

SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 …;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How does the OR operator differ from the AND operator?

A

A: OR requires at least one condition to be true, while AND requires all conditions to be true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Write a query to select all customers where the city is “Berlin,” the CustomerName starts with “G,” or the country is “Norway.”

A
SELECT * FROM Customers 
WHERE City = 'Berlin' OR CustomerName LIKE 'G%' OR Country = 'Norway';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: Can AND and OR operators be combined in the same SQL query?

A

A: Yes, they can be combined, often using parentheses for correct grouping.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Why are parentheses important when using AND and OR together?

A

A: They ensure the intended grouping of conditions, so SQL evaluates them in the correct order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: Write a query to select all Spanish customers with names starting with “G” or “R.”

A
SELECT * FROM Customers 
WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What can happen if parentheses are omitted in a combined AND/OR query?

A

A: SQL may misinterpret the grouping, returning unintended results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Write a query to select customers who are either from Spain and start with “G” or start with “R” regardless of country.

A
SELECT * FROM Customers 
WHERE Country = 'Spain' AND CustomerName LIKE 'G%' OR CustomerName LIKE 'R%';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly