W3. SQL Like Flashcards
Q: What does the SQL LIKE operator do?
A: It searches for a specified pattern in a column, often used with wildcards.
Q: Name two wildcards commonly used with the LIKE operator.
A: % (percent sign) for zero or more characters and _ (underscore) for a single character.
Q: Write a query to select all customers whose CustomerName starts with “a”.
SELECT * FROM Customers
WHERE CustomerName LIKE ‘a%’;
Q: What does the _ wildcard represent?
A: It represents a single character in a pattern.
Q: Write a query to find all customers from cities starting with “L” and following the pattern L_nd__.
SELECT * FROM Customers
WHERE City LIKE ‘L_nd__’;
Q: What does the % wildcard represent?
A: It represents any number of characters, including zero.
Q: Write a query to return all customers from a city containing the letter “L”.
SELECT * FROM Customers
WHERE City LIKE ‘%L%’;
Q: How do you search for records that start with a specific letter or phrase using LIKE?
A: Add % after the letter or phrase, e.g., LIKE ‘La%’.
Q: Write a query to select all customers whose CustomerName starts with “La”.
SELECT * FROM Customers
WHERE CustomerName LIKE ‘La%’;
Q: How do you search for records that end with a specific letter or phrase?
A: Add % before the letter or phrase, e.g., LIKE ‘%a’.
Q: Write a query to select all customers whose CustomerName ends with “a”.
SELECT * FROM Customers
WHERE CustomerName LIKE ‘%a’;
Q: How do you search for records that contain a specific letter or phrase?
A: Use % before and after the letter or phrase, e.g., LIKE ‘%or%’.
Q: Write a query to select all customers whose CustomerName contains “or”.
SELECT * FROM Customers
WHERE CustomerName LIKE ‘%or%’;
Q: Can wildcards % and _ be combined in LIKE?
A: Yes, you can combine them to create specific patterns.
Q: Write a query to select all customers whose CustomerName starts with “a” and is at least 3 characters long.
SELECT * FROM Customers
WHERE CustomerName LIKE ‘a__%’;