W3. SQL Wildcards Flashcards

1
Q

Q: What is a wildcard character in SQL?

A

A: It is used to substitute one or more characters in a string, often with the LIKE operator in a WHERE clause.

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

Q: Which wildcard character represents zero or more characters?

A

%

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

Q: Which wildcard character represents a single character?

A

_

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

Q: What does the [] wildcard do?

A

A: It matches any single character within the brackets.

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 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
6
Q

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

A

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

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 cities starting with any character, followed by “ondon”.

A

SELECT * FROM Customers
WHERE City LIKE ‘_ondon’;

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

Q: How do you use the [] wildcard to match specific characters?

A

A: Place characters within brackets, e.g., [bsp]% to match customers starting with “b”, “s”, or “p”.

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

Q: Write a query to select customers whose CustomerName starts with either “b”, “s”, or “p”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘[bsp]%’;

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

Q: What does the - wildcard do when used within []?

A

A: It specifies a range of characters.

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

Q: Write a query to select customers whose CustomerName starts with any letter from “a” to “f”.

A

SELECT * FROM Customers
WHERE CustomerName LIKE ‘[a-f]%’;

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

Q: How can % and _ be combined in a pattern?

A

A: They can be combined to create specific patterns, e.g., LIKE ‘a__%’ for names starting with “a” and at least 3 characters long.

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

Q: Write a query to return all customers that have “r” in the second position.

A

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

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

Q: If no wildcard is specified in LIKE, what happens?

A

A: The search requires an exact match.

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 from Spain using LIKE.

A

SELECT * FROM Customers
WHERE Country LIKE ‘Spain’;

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

Q: List some wildcards specific to Microsoft Access.

A
  • : zero or more characters
    ? : a single character
    [] : any character within brackets
    ! : any character not in brackets
    # : any single numeric character