SELECT column_name
FROM table_name
WHERE column_name=’condition’
ORDER BY columns
GROUP BY column_names
HAVING some_condition;
Customer Table
CustomerID, CustomerName, ContactName, Address, City, PostalCode, Country
SELECT
SELECT * FROM Customers; Returns all records and fields from Customer table.
SELECT CustomerName, City FROM Customers; Returns CustomerName,City of all records from Customer table.
SELECT * FROM Customers; Returns all records and fields from Customer table.
SELECT CustomerName, City FROM Customers; Returns CustomerName,City of all records from Customer table.
DISTINCT
SELECT DISTINCT Country FROM Customers;
Return Distinct Cities from Customer table. This means same country does not appear twice.
In above table Sri Lanka will return only once.
SELECT DISTINCT Country FROM Customers;
Return Distinct Cities from Customer table. This means same country does not appear twice.
In above table Sri Lanka will return only once.
WHERE
SELECT * FROM Customers WHERE Country='Mexico';
Return records with country =Mexico
Numeric fields don't use " marks
SELECT * FROM Customers WHERE CustomerID=1;
SELECT * FROM Customers WHERE Country='Mexico';
Return records with country =Mexico
Numeric fields don't use " marks
SELECT * FROM Customers WHERE CustomerID=1;
ORDER BY
SELECT * FROM Customers ORDER BY Country;
Records will return alphabetical order (A...Z)
SELECT * FROM Customers ORDER BY Country;
Records will return alphabetical order (A...Z)
GROUP BY
SELECT * FROM Customers GROUP BY Country;
Records will be grouped by Country
HAVING
SELECT * FROM CUSTOMERS GROUP BY age HAVING COUNT(age) >= 2;
Display record for which similar age count would be more than or equal to 2: