简体   繁体   中英

Select all rows where specific column value is maximum of that column

I want to select all columns(col1, col2, col3) where value of col3 is the maximum amongst all the values in col3.

For ex, for below table

col1 col2 col3
abc  def  2
ghi  jkl  3
mno  pqr  2
stu  vwx  3
yza  bcd  1

I want the output as

ghi  jkl  3
stu  vwx  3

How can I achieve this using SQL?

There are multiple ways to achieve this. One way is to use a sub-query to find the maximum value of col3 and then use it in getting the desired result.

SELECT * 
   FROM TABLE
WHERE col3 = (SELECT MAX(col3) FROM TABLE)

Try this-

SELECT * 
FROM your_table 
WHERE col3 = (SELECT MAX(col3) FROM your_table)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM