SQLite MAX Function in the Subquery
In this example, we will see how we can use the MAX function in a subquery to print the FirstName, LastName , and Salary of the Employee having the Maximum Salary. The generic Syntax while using the MAX function alongside Subquery is as follows –
SELECT
(Col1, Col2, Col3, ......, ColN)
FROM
Table_Name
WHERE
Column_Name = (SELECT MAX(Column_Name) FROM Table_Name);
The above syntax signifies how we can use MAX statement inside of a SubQuery to get our desired result
SELECT FirstName, LastName, Salary FROM Employees WHERE Salary = (SELECT MAX(Salary) FROM Employees);
Output:
The Output prints the FirstName, LastName and the Salary of that person who has the highest salary. In the query we are using a Subquery with the MAX function to get the maximum salary.
SQLite MAX() Function
MAX function is a type of Aggregate Function available in SQLite, which is primarily used to find out the maximum value from a given set (a column that is passed as its parameter). Other than that, the MAX function can also be used with other Aggregate functions like HAVING, GROUP BY, etc to sort or get some values that are obeying the condition mentioned by these other Aggregate Functions.
In this article, we will see how we can use the MAX function to do various tasks and how the MAX function can be used in various ways to get more precise outputs from the table.