Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want get nearest auto increment id. suppose i have input 3 the output must return 5
my table is:

id
1
3
5
7
Posted
Updated 3-Oct-13 21:25pm
v2
Comments
berrymaria 4-Oct-13 2:45am    
Umm, what do you mean? Could you please explain it more? What value would you like to get?
Mohibur Rashid 4-Oct-13 3:03am    
Your question is confusing.
but try this,
it might help
$result = mysql_query("SHOW TABLE STATUS LIKE 'table_name'");
$row = mysql_fetch_array($result);
$nextId = $row['Auto_increment'];
mysql_free_result($result);
Mohibur Rashid 4-Oct-13 3:39am    
so?
SELECT id FROM TABLE WHERE id>'3' ORDER BY id ASC LIMIT 0,1

return input + increment value
for example input=3 and increment value=2
nearest next=3+2=5
 
Share this answer
 
SQL
SELECT MIN( id )
FROM [table]
WHERE id >3
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900