在网上查了下,基本都是通过id获取,但我现在有个需求,表结构类似这样:
name | age | sex
simon 23 1
nancy 20 2
请问各位,这种没有id号,以name作主键的表如何通过sql获取某条数据(比如name=simon)的下一条数据?
伊谢尔伦2017-04-17 11:19:55
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.