Examples Using GREATEST Function

Example 1: Let’s Say We Have a Table Called “Students” with the Following Data

We can create the Students table using the following code which defines the table structure with columns such as Stu_name, hindi, English and maths as Columns.

Query:

CREATE TABLE students (
Stu_name VARCHAR(50),
hindi INT,
english INT,
maths INT
);
INSERT INTO students (Stu_name, hindi, english, maths) VALUES
('John', 85, 90, 95),
('Alice', 78, 92, 88),
('Bob', 92, 85, 90),
('Emma', 80, 88, 92),
('Michael', 95, 82, 89);

Output:

Students Table

Suppose we have to find the maximum mark for each student. we have to find the maximum mark for each student using the following query.

Query:

SELECT Stu_name, 
GREATEST(hindi, english, maths) AS max_mark
FROM students;

Output:

Output

Explanation: We can observe that the desired output is obtained.

How to Find the Maximum of Multiple Columns in PL/SQL?

In PL/SQL finding the maximum value of multiple columns is a common requirement for maintaining the database. This operation is important for various applications, ranging from financial analysis to data reporting. In this article, we will learn about How to find the maximum of multiple columns in PL/SQL with the help of two different methods to resolve problems by various examples and so on.

Similar Reads

Using GREATEST Function

To find the maximum of multiple columns in PL/SQL, the GREATEST function is utilized. This function compares multiple expressions and returns the greatest value among them. The syntax for using the GREATEST function is as follows:...

Examples Using GREATEST Function

Example 1: Let’s Say We Have a Table Called “Students” with the Following Data...

Using CASE Statement

An alternative approach to finding the maximum value of multiple columns in PL/SQL is by using the CASE statement. The syntax for using the CASE statement to find the maximum value is as follows....

Conclusion

Overall we can say that by understanding both the GREATEST function and the CASE statement we can effectively find the maximum value among multiple columns in PL/SQL. Each approach offers unique advantages and can be applied based on specific requirements also providing flexibility and control in determining the maximum values....

Contact Us