Ad

Ad

Monday, 5 May 2014

jQuery Tutorial

"Try it yourself" Examples in Each Chapter

With our online editor, you can edit the code, and click on a button to view the result.

Example

$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});

Try it yourself »
Click on the "Try it yourself" button to see how it works.

jQuery Examples

Learn by examples! At W3Schools you will find a lot of jQuery examples to edit and test yourself.


jQuery References

At W3Schools you will find a complete reference of all jQuery objects and methods.

Sunday, 4 May 2014

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 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
1
Alfreds 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
4
Around 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 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
1
Alfreds 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
4
Around 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;

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