Or / are :
SELECT * FROM Customers
WHERE City='Berlin' OR City='München';
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
IN command:
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
Distinct & Count :
SELECT DISTINCT Country FROM Customers;
SELECT COUNT(DISTINCT Country) FROM Customers;
SELECT COUNT(*)
FROM Products;
NOT Operator:
SELECT * FROM Customers
WHERE NOT Country='Germany';
Null & not null
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;
SQL MIN() and MAX()
SELECT MIN(Price)
FROM Products;
Avg & sum
SELECT AVG(Price)
FROM Products;
SELECT SUM(Quantity)
FROM OrderDetails;
LIKE:
Customer name starting with ‘a’:
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';
Customer name ending with ‘a’:
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
Customer name any position with ‘or’:
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%'
Selecting ‘r’ in the second position:
SELECT * FROM Customers
WHERE CustomerName LIKE '_r%';
Starting with ‘a’ and end with ‘o’:
SELECT * FROM Customers
WHERE ContactName LIKE 'a%o';
Name doesn’t start with ‘a’:
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'a%';