3rd Year Elite SQL 3&4
3rd Year Elite SQL 3&4
–3&4
Mr. Sai Sushanth Durvasula
SQL Query as a way to solve a problem!
Transformation(s)
Input Output
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE Customers
SET PostalCode = 05344
WHERE Country = ’UK';
Remove records from table - DELETE
DELETE statement is used to delete the existing records in a table.
DELETE
FROM table_name
WHERE condition;
Be careful when deleting records in a table! Notice
the WHERE clause in the DELETE statement.
SELECT *
FROM Customers
WHERE CustomerName LIKE 'a%';
Return all customers from a city that starts with ‘I' followed
by one wildcard character, then ‘d' and then two wildcard
characters:
SELECT *
FROM Customers
WHERE country LIKE ’I_d__';
The % Wildcard
The % wildcard represents any number of characters, even
zero characters.
Return all customers from a city that contains the letter 'L':
SELECT *
FROM Customers
WHERE country LIKE ’%L%';
SELECT *
FROM Customers
WHERE CustomerName LIKE ’Al%';
The % Wildcard
You can also combine any number of conditions using
AND or OR operators
SELECT *
FROM Customers
WHERE CustomerName LIKE 'a%’ OR
CustomerName LIKE 'b%';
Return all customers that starts with "b" and ends
with "s":
SELECT *
FROM Customers
WHERE CustomerName LIKE ’b%s’;
SELECT *
FROM Customers
WHERE Country LIKE ‘India’;
LIMIT Clause
The LIMIT clause is used to specify the no.of records to return
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;
The following SQL statement selects the first three
records from the "Customers" table:
SELECT *
FROM Customers
LIMIT 3;
What if we want to select records 4 - 6 (inclusive)?
MySQL provides a way to handle this: by using
OFFSET.
SELECT *
FROM Customers
LIMIT 3 OFFSET 3;
ORDER BY Keyword