溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

mysql怎么查詢下一條數(shù)據(jù)

發(fā)布時(shí)間:2020-11-13 10:12:22 來源:億速云 閱讀:564 作者:小新 欄目:MySQL數(shù)據(jù)庫

小編給大家分享一下mysql怎么查詢下一條數(shù)據(jù),希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

mysql查詢下一條數(shù)據(jù)的方法:從news表里按從小到大的順序選擇一條比當(dāng)前ID大的數(shù)據(jù),代碼為【table_a where id = (select min(id) from table_a where id > {$id})】。

mysql查詢下一條數(shù)據(jù)的方法:

獲取當(dāng)前文件下一條記錄的原理是下一條的sql語句,從news表里按從小到大的順序選擇一條比當(dāng)前ID大的數(shù)據(jù)。

如果ID是主鍵或者有索引,可以直接查找:

方法1:

1.select * from table_a where id = (select id from table_a where id < {$id} order by id desc limit 1);   
2.select * from table_a where id = (select id from table_a where id > {$id} order by id asc limit 1);

方法2:

1.select * from table_a where id = (select max(id) from table_a where id < {$id});   
2.select * from table_a where id = (select min(id) from table_a where id > {$id});

看完了這篇文章,相信你對(duì)mysql怎么查詢下一條數(shù)據(jù)有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI