简体   繁体   中英

Get the value of the column of which the Serial no is greatest

I have a table(table_name), the columns of which are Sno,count. If wanna get the value of the count column where Sno is, say 1..

SELECT count FROM `table_name` WHERE Sno=1;

gives

count
 2

it works!!!

But what if I wanna get the value of count where Sno is Max?

Sno  count
 1    2
 2    1

Basically I need help creating hybrid of :

SELECT count FROM `table_name` WHERE Sno=1;

&

select MAX(Sno) from table_name;

You can use order by and limit :

SELECT t.*
FROM `table_name` t
ORDER BY Sno DESC
LIMIT 1;

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