Mysql method of querying the next piece of data: Select a piece of data larger than the current ID from the news table in ascending order. The code is [table_a where id = (select min(id) from table_a where id) > {$id})].
Mysql method of querying the next data:
The principle of getting the next record of the current file is the next one SQL statement, select a piece of data larger than the current ID from the news table in ascending order.
If the ID is a primary key or has an index, you can search directly:
Method 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);
Method 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});
More related Free learning recommendations: mysql tutorial(video)
The above is the detailed content of How to query the next data in mysql. For more information, please follow other related articles on the PHP Chinese website!