I have a table called courses. The fields are:
id, category, sortorder, fullname, etc.....
What I am trying to do is given the category I want to find the maximum sortorder number in that category and then increment that number and use this new number for my new row.
For example: I have category = 30 and it will return the numbers 1 to 10. I want to retrieve 10 because it is the highest number but I don’t know what the highest number will actually be in each query. After I get the value 10 I will add 1 to it and then use it for my new course.
How should I do this ?
Thanks!
You can use the
MAX()function of MySQL.So do something like: