SQLite MAX Function

SQLite MAX function is used to fetch the maximum value of an expression.

Syntax:

snippet
SELECT MAX(aggregate_expression)
FROM tables
[WHERE conditions];

Syntax when you use MAX function with GROUP BY clause:

snippet
SELECT expression1, expression2, ... expression_n
MAX(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;

Example1:

We have a table named "STUDENT", having the following data:

Sqlite Max function 1

Retrieve the highest fees of the student from the "STUDENT" table.

Output:

Sqlite Max function 2

Example2:

Using GROUP BY clause with MAX function:

Retrieve NAME, CITY and MAX FEES from the table "STUDENT" and ORDER BY the data by CITY:

snippet
SELECT NAME, ADDRESS, MAX(FEES) AS "Highest FEES"
FROM STUDENT
WHERE ID <= 5
GROUP BY ADDRESS;

Output:

Sqlite Max function 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +