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; 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;

Read More

Posted in SQL Tagged Comments Off on SQL MIN() Function
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; 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;

Read More

Posted in SQL Tagged Comments Off on SQL MAX() Function
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_name ORDER 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…

Read More

Posted in SQL Tagged Comments Off on SQL LAST() Function
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_name ORDER 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…

Read More

Posted in SQL Tagged Comments Off on SQL FIRST() Function
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;…

Read More

Posted in SQL Tagged Comments Off on SQL COUNT() Function
SQL AVG() Function

The AVG() function returns the average value of a numeric column. SQL AVG() Syntax SELECT AVG(column_name) FROM table_name 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; 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);

Read More

Posted in SQL Tagged Comments Off on SQL AVG() Function