How to use Set Operator MINUS to Select Rows with Max Value In SQL
To retrieve unique rows from the first query that do not appear in the second query using the MINUS set operator in SQL:
Query:
SELECT * FROM Teacher MINUS SELECT t1.* FROM Teacher t1, Teacher t2 WHERE t1.Salary < t2.Salary;
Output:
Explanation:
Like the previous subquery, we’ll find the row with a salary less than that of any other teacher’s salary. Then we will do the set difference operation of the table that we have found (Rows not having maximum salary) on Teacher table to find the complement of table which we found to find the rows having a maximum salary.
How to Select Row With Max Value on a Column in SQL?
SQL is a powerful language for managing and handling relational databases. A common query requirement in relational databases is to get rows with the max value in a particular column. Here, we’ll look at different ways to do this, depending on different situations and database environments.
In this article, we will see SQL queries to select row with maximum value in one column.