LARGE
LARGE is an aggregate function in SQL. It retrieves the nth largest value from a particular column or a dataset. It is quite helpful when you need to find a value based on its rank without ordering or sorting the data.
Example
CREATE TABLE Employees ( ID int, Salary int);
INSERT INTO Employees (ID, Salary)VALUES (1, 5000), (2, 3000), (3, 4500), (4, 6000), (5, 10000);
SELECT MAX(Salary) AS Largest_Salary FROM Employees;
Output
Largest_Salary10000
Explanation
The SQL query above first creates an ‘Employees’ table with ‘ID’ and ‘Salary’ as columns. It then inserts 5 records into the table. The MAX
function is finally used to find the largest salary, which in this case is 10000
.
Example
SELECT MAX(Size) AS LargestSizeFROM Products;
Output
LargestSize----------3500
Explanation
This SQL code retrieves the largest Size
value from the Products
table, using the MAX
function to find the maximum value within the Size
column.
Example
SELECT MAX(Salary) AS LargestSalaryFROM Employees;
Output
LARGESTSALARY-------------50000
Explanation
In this example, we use the Oracle SQL MAX()
function to find the highest number in the Salary
column of the Employees
table. The column alias LargestSalary
is used for the returned value. The largest value in the Salary
column is returned as the result.