I'm trying to generate a new number/next number depending on the last number inserted into my db???
In my DB I have a column where the numbers look like this:
00001.00001
00001.00002
00001.00003
00002
00003.00001
00004
etc. etc.
This is done for pages to find its place in a hierarchy.
My question is as follows:
Is it possible to make a script that looks into the dbtable and finds out what the last number in ex. 00001.xxxxx, and then generates the next comming number? And if yes... How.
Generate number depending on last insert!??
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You could use MAX() if it was only numbers (I don't believe MAX() works with strings, although it might), but instead, you could order the selections starting with the latest, and then select the first of that set (which is the latest entry).
Code: Select all
select from `table` order by `column` desc limit 1;- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Sounds like you're in need of a better database design.
Also, maybe MySQL's SUBSTR() could be of use.
Also, maybe MySQL's SUBSTR() could be of use.
Code: Select all
SELECT FROM `table` WHERE SUBSTR(`column`, 0, 6) = '00001.' ORDER BY `column` DESC LIMIT 1;- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: