All,
I'm trying to write a PHP function that creates a new unique ID by simply incrementing the current largest (highest) one in a column. I have a column ID in the table SPECIMEN, with ID being an INTEGER, unique, and a primary key. Basically, all I want the SQL query to do is return the "ID" value of the row that has the highest "ID" value... my function will then add one and do the insert. I'm doing this instead of AUTOINCREMENT because of portability issues. Here's my query that's failing:
SELECT id FROM specimen WHERE ID=(SELECT MAX(ID) FROM specimen)
mySQL is giving me an error, saying there's a syntax error... when I run "SELECT MAX(ID) FROM specimen" I get "18", but when I try to do a subquery using it as the ID argument, it fails... does mySQL simply not support this??
Thanks!
p.s. -- I'm running this in the mySQL command line...