mysql - 如何使用sql获取上一条和下一条数据
迷茫
迷茫 2017-04-17 11:17:55
0
1
807

在网上查了下,基本都是通过id获取,但我现在有个需求,表结构类似这样:
name | age | sex
simon 23 1
nancy 20 2

请问各位,这种没有id号,以name作主键的表如何通过sql获取某条数据(比如name=simon)的下一条数据?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
伊谢尔伦

Records in database tables are stored in sets. The database cannot guarantee that the order in which records are stored is the order in which you insert records.

So according to what you said, if you want to get the previous or next record of a record, you must use the order clause to sort the retrieved results, and then use the limit clause to get the record at the corresponding position.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template