W3. SQL Like Flashcards

1
Q

Q: What does the SQL LIKE operator do?

A

A: It searches for a specified pattern in a column, often used with wildcards.

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

Q: Name two wildcards commonly used with the LIKE operator.

A

A: % (percent sign) for zero or more characters and _ (underscore) for a single character.

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

Q: Write a query to select all customers whose CustomerName starts with “a”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘a%’;

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

Q: What does the _ wildcard represent?

A

A: It represents a single character in a pattern.

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

Q: Write a query to find all customers from cities starting with “L” and following the pattern L_nd__.

A

SELECT * FROM Customers
WHERE City LIKE ‘L_nd__’;

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

Q: What does the % wildcard represent?

A

A: It represents any number of characters, including zero.

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

Q: Write a query to return all customers from a city containing the letter “L”.

A

SELECT * FROM Customers
WHERE City LIKE ‘%L%’;

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

Q: How do you search for records that start with a specific letter or phrase using LIKE?

A

A: Add % after the letter or phrase, e.g., LIKE ‘La%’.

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

Q: Write a query to select all customers whose CustomerName starts with “La”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘La%’;

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

Q: How do you search for records that end with a specific letter or phrase?

A

A: Add % before the letter or phrase, e.g., LIKE ‘%a’.

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

Q: Write a query to select all customers whose CustomerName ends with “a”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘%a’;

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

Q: How do you search for records that contain a specific letter or phrase?

A

A: Use % before and after the letter or phrase, e.g., LIKE ‘%or%’.

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

Q: Write a query to select all customers whose CustomerName contains “or”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘%or%’;

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

Q: Can wildcards % and _ be combined in LIKE?

A

A: Yes, you can combine them to create specific patterns.

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

Q: Write a query to select all customers whose CustomerName starts with “a” and is at least 3 characters long.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘a__%’;

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

Q: Write a query to select all customers with “r” in the second position of CustomerName.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘_r%’;

17
Q

Q: What happens if no wildcard is specified in LIKE?

A

A: The search requires an exact match.

18
Q

Q: Write a query to return all customers from Spain using LIKE.

A

SELECT * FROM Customers
WHERE Country LIKE ‘Spain’;