共計(jì) 659 個(gè)字符,預(yù)計(jì)需要花費(fèi) 2 分鐘才能閱讀完成。
自動(dòng)寫代碼機(jī)器人,免費(fèi)開通
丸趣 TV 小編給大家分享一下 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)注丸趣 TV 行業(yè)資訊頻道,感謝各位的閱讀!
向 AI 問一下細(xì)節(jié)
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完