SQL Statement 2 Flashcards
Select all customers that starts with the letter “a”;
SELECT * FROM Customers WHERE CustomerName LIKE ‘a%’;
Return all customers from a city that starts with ‘L’ followed by one wildcard character, then ‘nd’ and then two wildcard characters:
SELECT * FROM Customers WHERE city LIKE ‘L_nd__’;
The % wildcard represents any number of characters, even zero
characters.
Return all customers that starts with ‘La’:
SELECT * FROM Customers WHERE CustomerName LIKE ‘La%’;
Return all customers that starts with ‘a’ or starts with ‘b’:
SELECT * FROM Customers WHERE CustomerName LIKE ‘a%’ OR
CustomerName LIKE ‘b%’;
Return all customers that ends with ‘a’:
SELECT * FROM Customers WHERE CustomerName LIKE ‘%a’;
Return all customers from a city that contains the letter ‘L’:
SELECT * FROM Customers WHERE city LIKE ‘%L%’;
SELECT in Return all customers from ‘Germany’, ‘France’, or ‘UK’
SELECT * FROM Customers WHERE Country IN (‘Germany’, ‘France’, ‘UK’);
Return all customers from ‘Germany’, ‘France’, or ‘UK’
SELECT * FROM Customers WHERE Country NOT IN (‘Germany’, ‘France’,
‘UK’);
SELECT NOT Select only the customers that are NOT from Spain:
Syntax
SELECT column1, column2, …
FROM table_name
WHERE NOT condition;
SELECT * FROM Customers
WHERE NOT Country = ‘Spain’;
Condition Not Like
SELECT NOT LIKE SELECT * FROM Customers
WHERE CustomerName NOT LIKE ‘A%’