21 November 2014

SQL Functions


SQL Functions


SQL has many built-in functions for performing calculations on data.

SQL Aggregate Functions

SQL aggregate functions return a single value, calculated from values in a column.
Useful aggregate functions:
  • AVG() - Returns the average value
  • COUNT() - Returns the number of rows
  • FIRST() - Returns the first value
  • LAST() - Returns the last value
  • MAX() - Returns the largest value
  • MIN() - Returns the smallest value
  • SUM() - Returns the sum

SQL Scalar functions

SQL scalar functions return a single value, based on the input value.
Useful scalar functions:
  • UCASE() - Converts a field to upper case
  • LCASE() - Converts a field to lower case
  • MID() - Extract characters from a text field
  • LEN() - Returns the length of a text field
  • ROUND() - Rounds a numeric field to the number of decimals specified
  • NOW() - Returns the current system date and time
  • FORMAT() - Formats how a field is to be displayed
Tip: The aggregate functions and the scalar functions will be explained in details in the next chapters.

SQL AVG() Function

The AVG() Function

The AVG() function returns the average value of a numeric column.

SQL AVG() Syntax

SELECT AVG(column_name) FROM table_name


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL AVG() Example

The following SQL statement gets the average value of the "Price" column from the "Products" table:

Example

SELECT AVG(Price) AS PriceAverage FROM Products;

Try it yourself »
The following SQL statement selects the "ProductName" and "Price" records that have an above average price:

Example

SELECT ProductName, Price FROM Products
WHERE Price>(SELECT AVG(Price) FROM Products);

Try it yourself »

SQL COUNT() Function

The COUNT() function returns the number of rows that matches a specified criteria.

SQL COUNT(column_name) Syntax

The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
SELECT COUNT(column_name) FROM table_name;

SQL COUNT(*) Syntax

The COUNT(*) function returns the number of records in a table:
SELECT COUNT(*) FROM table_name;

SQL COUNT(DISTINCT column_name) Syntax

The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
SELECT COUNT(DISTINCT column_name) FROM table_name;
Note: COUNT(DISTINCT) works with ORACLE and Microsoft SQL Server, but not with Microsoft Access.

Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
OrderIDCustomerIDEmployeeIDOrderDateShipperID
10265721996-07-251
102668731996-07-263
102672541996-07-291


SQL COUNT(column_name) Example

The following SQL statement counts the number of orders from "CustomerID"=7 from the "Orders" table:

Example

SELECT COUNT(CustomerID) AS OrdersFromCustomerID7 FROM Orders
WHERE CustomerID=7;

Try it yourself »


SQL COUNT(*) Example

The following SQL statement counts the total number of orders in the "Orders" table:

Example

SELECT COUNT(*) AS NumberOfOrders FROM Orders;

Try it yourself »

SQL COUNT(DISTINCT column_name) Example

The following SQL statement counts the number of unique customers in the "Orders" table:

Example

SELECT COUNT(DISTINCT CustomerID) AS NumberOfCustomers FROM Orders;

Try it yourself »

SQL FIRST() Function

The FIRST() Function

The FIRST() function returns the first value of the selected column.

SQL FIRST() Syntax

SELECT FIRST(column_name) FROM table_name;
Note: The FIRST() function is only supported in MS Access.

SQL FIRST() Workaround in SQL Server, MySQL and Oracle

SQL Server Syntax

SELECT TOP 1 column_name FROM table_nameORDER BY column_name ASC;

Example

SELECT TOP 1 CustomerName FROM Customers
ORDER BY CustomerID ASC;

MySQL Syntax

SELECT column_name FROM table_name
ORDER BY column_name ASC
LIMIT 1;

Example

SELECT CustomerName FROM Customers
ORDER BY CustomerID ASC
LIMIT 1;

Oracle Syntax

SELECT column_name FROM table_name
ORDER BY column_name ASC
WHERE ROWNUM <=1;

Example

SELECT CustomerName FROM Customers
ORDER BY CustomerID ASC
WHERE ROWNUM <=1;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL FIRST() Example

The following SQL statement selects the first value of the "CustomerName" column from the "Customers" table:

Example

SELECT FIRST(CustomerName) AS FirstCustomer FROM Customers;

SQL LAST() Function

The LAST() Function

The LAST() function returns the last value of the selected column.

SQL LAST() Syntax

SELECT LAST(column_name) FROM table_name;
Note: The LAST() function is only supported in MS Access.

SQL LAST() Workaround in SQL Server, MySQL and Oracle

SQL Server Syntax

SELECT TOP 1 column_name FROM table_nameORDER BY column_name DESC;

Example

SELECT TOP 1 CustomerName FROM Customers
ORDER BY CustomerID DESC;

MySQL Syntax

SELECT column_name FROM table_name
ORDER BY column_name DESC
LIMIT 1;

Example

SELECT CustomerName FROM Customers
ORDER BY CustomerID DESC
LIMIT 1;

Oracle Syntax

SELECT column_name FROM table_name
ORDER BY column_name DESC
WHERE ROWNUM <=1;

Example

SELECT CustomerName FROM Customers
ORDER BY CustomerID DESC
WHERE ROWNUM <=1;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL LAST() Example

The following SQL statement selects the last value of the "CustomerName" column from the "Customers" table:

Example

SELECT LAST(CustomerName) AS LastCustomer FROM Customers;

Try it yourself »


SQL MAX() Function

The MAX() Function

The MAX() function returns the largest value of the selected column.

SQL MAX() Syntax

SELECT MAX(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL MAX() Example

The following SQL statement gets the largest value of the "Price" column from the "Products" table:

Example

SELECT MAX(Price) AS HighestPrice FROM Products;

Try it yourself »

SQL MIN() Function

The MIN() Function

The MIN() function returns the smallest value of the selected column.

SQL MIN() Syntax

SELECT MIN(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL MIN() Example

The following SQL statement gets the smallest value of the "Price" column from the "Products" table:

Example

SELECT MIN(Price) AS SmallestOrderPrice FROM Products;

Try it yourself »

SQL SUM() Function

The SUM() Function

The SUM() function returns the total sum of a numeric column.

SQL SUM() Syntax

SELECT SUM(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "OrderDetails" table:
OrderDetailIDOrderIDProductIDQuantity
1102481112
2102484210
310248725
410249149
5102495140


SQL SUM() Example

The following SQL statement finds the sum of all the "Quantity" fields for the "OrderDetails" table:

Example

SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;

Try it yourself »

SQL GROUP BY Statement

Aggregate functions often need an added GROUP BY statement.

The GROUP BY Statement

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

SQL GROUP BY Syntax

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
OrderIDCustomerIDEmployeeIDOrderDateShipperID
102489051996-07-043
102498161996-07-051
102503441996-07-082
And a selection from the "Shippers" table:
ShipperIDShipperNamePhone
1Speedy Express(503) 555-9831
2United Package(503) 555-3199
3Federal Shipping(503) 555-9931
And a selection from the "Employees" table:
EmployeeIDLastNameFirstNameBirthDatePhotoNotes
1DavolioNancy1968-12-08EmpID1.picEducation includes a BA....
2FullerAndrew1952-02-19EmpID2.picAndrew received his BTS....
3LeverlingJanet1963-08-30EmpID3.picJanet has a BS degree....


SQL GROUP BY Example

Now we want to find the number of orders sent by each shipper.
The following SQL statement counts as orders grouped by shippers:

Example

SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID
GROUP BY ShipperName;

Try it yourself »


GROUP BY More Than One Column

We can also use the GROUP BY statement on more than one column, like this:

Example

SELECT Shippers.ShipperName, Employees.LastName,
COUNT(Orders.OrderID) AS NumberOfOrders
FROM ((Orders
INNER JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID)
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY ShipperName,LastName;

Try it yourself »

SQL HAVING Clause

The HAVING Clause

The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

SQL HAVING Syntax

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
OrderIDCustomerIDEmployeeIDOrderDateShipperID
102489051996-07-043
102498161996-07-051
102503441996-07-082
And a selection from the "Employees" table:
EmployeeIDLastNameFirstNameBirthDatePhotoNotes
1DavolioNancy1968-12-08EmpID1.picEducation includes a BA....
2FullerAndrew1952-02-19EmpID2.picAndrew received his BTS....
3LeverlingJanet1963-08-30EmpID3.picJanet has a BS degree....


SQL HAVING Example

Now we want to find if any of the customers have a total order of less than 2000.
We use the following SQL statement:
The following SQL statement finds if any of the employees has registered more than 10 orders:

Example

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;

Try it yourself »
Now we want to find if the employees "Davolio" or "Fuller" have more than 25 orders.
We add an ordinary WHERE clause to the SQL statement:

Example

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID
WHERE LastName='Davolio' OR LastName='Fuller'
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 25;

Try it yourself »

SQL UCASE() Function

The UCASE() Function

The UCASE() function converts the value of a field to uppercase.

SQL UCASE() Syntax

SELECT UCASE(column_name) FROM table_name;

Syntax for SQL Server

SELECT UPPER(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL UCASE() Example

The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table, and converts the "CustomerName" column to uppercase:

Example

SELECT UCASE(CustomerName) AS Customer, City
FROM Customers;

Try it yourself »

SQL LCASE() Function

The LCASE() Function

The LCASE() function converts the value of a field to lowercase.

SQL LCASE() Syntax

SELECT LCASE(column_name) FROM table_name;

Syntax for SQL Server

SELECT LOWER(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL LCASE() Example

The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table, and converts the "CustomerName" column to lowercase:

Example

SELECT LCASE(CustomerName) AS Customer, City
FROM Customers;

Try it yourself »

SQL MID() Function

The MID() Function

The MID() function is used to extract characters from a text field.

SQL MID() Syntax

SELECT MID(column_name,start[,length]) AS some_name FROM table_name;

ParameterDescription
column_nameRequired. The field to extract characters from
startRequired. Specifies the starting position (starts at 1)
lengthOptional. The number of characters to return. If omitted, the MID() function returns the rest of the text
Note: The equivalent function for SQL Server is SUBSTRING():
SELECT SUBSTRING(column_name,start,length) AS some_name FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL MID() Example

The following SQL statement selects the first four characters from the "City" column from the "Customers" table:

Example

SELECT MID(City,1,4) AS ShortCity
FROM Customers;

Try it yourself »

SQL LEN() Function

The LEN() Function

The LEN() function returns the length of the value in a text field.

SQL LEN() Syntax

SELECT LEN(column_name) FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden


SQL LEN() Example

The following SQL statement selects the "CustomerName" and the length of the values in the "Address" column from the "Customers" table:

Example

SELECT CustomerName,LEN(Address) as LengthOfAddress
FROM Customers;

Try it yourself »

SQL ROUND() Function

The ROUND() Function

The ROUND() function is used to round a numeric field to the number of decimals specified.
Note: Some database systems do rounding differently than would typically be considered. Most people assume that the ROUND() function would round to the nearest whole number. However, many DBMS's do "Bankers Rounding". This means that the number being rounded is rounded to the nearest EVEN whole number. I.E. if the number being rounded was 11.3, the logical rounding to most people would be to 11. However, since 11 is odd, "Bankers Rounding" would round this number to 12 instead.

SQL ROUND() Syntax

SELECT ROUND(column_name,decimals) FROM table_name;

ParameterDescription
column_nameRequired. The field to round.
decimalsRequired. Specifies the number of decimals to be returned.


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL ROUND() Example

The following SQL statement selects the product name and rounds the price in the "Products" table:

Example

SELECT ProductName, ROUND(Price,0) AS RoundedPrice
FROM Products;

Try it yourself »

SQL NOW() Function

The NOW() Function

The NOW() function returns the current system date and time.

SQL NOW() Syntax

SELECT NOW() FROM table_name;


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL NOW() Example

The following SQL statement selects the product name, and price for today from the "Products" table:

Example

SELECT ProductName, Price, Now() AS PerDate
FROM Products;

Try it yourself »

SQL FORMAT() Function

The FORMAT() Function

The FORMAT() function is used to format how a field is to be displayed.

SQL FORMAT() Syntax

SELECT FORMAT(column_name,format) FROM table_name;

ParameterDescription
column_nameRequired. The field to be formatted.
formatRequired. Specifies the format.


Demo Database

In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25


SQL FORMAT() Example

The following SQL statement selects the product name, and price for today (formatted like YYYY-MM-DD) from the "Products" table:

Example

SELECT ProductName, Price, FORMAT(Now(),'YYYY-MM-DD') AS PerDate
FROM Products;

Try it yourself »

SQL Quick Reference

SQL StatementSyntax
AND / ORSELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
ALTER TABLEALTER TABLE table_name
ADD column_name datatype
or
ALTER TABLE table_name
DROP COLUMN column_name
AS (alias)SELECT column_name AS column_alias
FROM table_name
or
SELECT column_name
FROM table_name  AS table_alias
BETWEENSELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
CREATE DATABASECREATE DATABASE database_name
CREATE TABLECREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name2 data_type,
...
)
CREATE INDEXCREATE INDEX index_name
ON table_name (column_name)
or
CREATE UNIQUE INDEX index_name
ON table_name (column_name)
CREATE VIEWCREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
DELETEDELETE FROM table_name
WHERE some_column=some_value
or
DELETE FROM table_name
(Note: Deletes the entire table!!)
DELETE * FROM table_name
(Note: Deletes the entire table!!)
DROP DATABASEDROP DATABASE database_name
DROP INDEXDROP INDEX table_name.index_name (SQL Server)
DROP INDEX index_name ON table_name (MS Access)
DROP INDEX index_name (DB2/Oracle)
ALTER TABLE table_name
DROP INDEX index_name (MySQL)
DROP TABLEDROP TABLE table_name
EXISTSIF EXISTS (SELECT * FROM table_name WHERE id = ?)
BEGIN
--do what needs to be done if exists
END
ELSE
BEGIN
--do what needs to be done if not
END
GROUP BYSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVINGSELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
INSELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
INSERT INTOINSERT INTO table_name
VALUES (value1, value2, value3,....)
or
INSERT INTO table_name
(column1, column2, column3,...)
VALUES (value1, value2, value3,....)
INNER JOINSELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
LEFT JOINSELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
RIGHT JOINSELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
FULL JOINSELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
LIKESELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
ORDER BYSELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC|DESC]
SELECTSELECT column_name(s)
FROM table_name
SELECT *SELECT *
FROM table_name
SELECT DISTINCTSELECT DISTINCT column_name(s)
FROM table_name
SELECT INTOSELECT *
INTO new_table_name [IN externaldatabase]
FROM old_table_name
or
SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name
SELECT TOPSELECT TOP number|percent column_name(s)
FROM table_name
TRUNCATE TABLETRUNCATE TABLE table_name
UNIONSELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
UNION ALLSELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
UPDATEUPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value
WHERESELECT column_name(s)
FROM table_name
WHERE column_name operator value


No comments: