W3. SQL And Flashcards

1
Q

Q: What does the SQL AND operator do?

A

A: It filters records based on multiple conditions, returning records only if all conditions are 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 Spain with names that start with “G.”

A
SELECT * FROM Customers 
WHERE Country = 'Spain' AND CustomerName LIKE 'G%';
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 AND conditions in SQL?

A

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

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

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

A

A: AND requires all conditions to be true, while OR requires only one condition 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 from Germany, in Berlin, with a PostalCode higher than 12000.

A
SELECT * FROM Customers 
WHERE Country = 'Germany' AND City = 'Berlin' AND PostalCode > 12000;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: Can you combine AND and OR operators in the same SQL query?

A

A: Yes, they can be combined, often with parentheses to ensure the correct order of conditions.

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 clarify grouping, ensuring that conditions are evaluated in the intended 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 happens if you omit parentheses when combining AND and OR?

A

A: SQL may misinterpret the intended condition grouping, potentially returning incorrect results.

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

Q: Write a query that returns customers who are either from Spain and start with “G” or start with “R” regardless of their 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