insert into enrolls (section_id,total)
values(324,max(sub) +.1);
how can I make it work so the value for the total of this entry is the max of the sub column from the same table + .1
i've tried: values(324,(SELECT max(sub) FROM enrolls) +.1);
but it does not work because its against the rules to take the max from the same table your inserting into.
Inserting data into a table (subselect?)
Moderator: General Moderators
- Templeton Peck
- Forum Commoner
- Posts: 45
- Joined: Sun May 11, 2003 7:51 pm
I think you should using code in php because a complex query will slower excute than simple query:
Code: Select all
$rs = mysql_query("Select Max(sub) from enrolls");
list($maxVal) = mysql_fetch_row($rs);
mysql_query("Insert into enrolls (section_id,total) values(324,($maxVal +.1)");