Home >Database >Mysql Tutorial >How to Find the Second Largest Value in a SQL Column with Duplicates?
Extracting the Second Highest Value from a SQL Column
This guide demonstrates how to retrieve the second largest integer value from a specific table column, handling potential duplicate values.
A concise and efficient SQL query achieves this:
<code class="language-sql">SELECT MAX(col) FROM table WHERE col < (SELECT MAX(col) FROM table);</code>
This query leverages a subquery to find the maximum value and then uses the MAX
function again to find the largest value that is strictly less than the maximum. This approach effectively addresses the issue of duplicate maximum values, ensuring accurate retrieval of the second largest value.
The above is the detailed content of How to Find the Second Largest Value in a SQL Column with Duplicates?. For more information, please follow other related articles on the PHP Chinese website!