2017-01-19 32 views
-3

我有這樣的表稱爲 「tblpercentage」mysql select max percent id和all row。或者選擇最新的插入

PercentID Dividend Rebates  Interest 
    1   40   10   2 
    2   60   20   5  

這是我的查詢

SELECT MAX(PercentID)As PercentID,Interest FROM tblpercentage 

但問題是。它只能選擇PercentID = 2和interest = 2,而不是5,但我想要的是選擇帶有最大ID的所有行。誰能幫我。

+2

見http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve -for - 什麼 - 似乎對我將要-A-極簡單的SQL查詢 – Strawberry

回答

0

用於獲取有關最大ID行,你應該使用子查詢

select PercentID,Interest from tblpercentage 
    where PercentID = (SELECT MAX(PercentID) from tblpercentage)