PDA

View Full Version : Inserting Data into a table


Templeton Peck
06-05-2003, 07:13 AM
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?

raf
06-05-2003, 01:01 PM
You'll need a subquery ('subselect' in MySQL-manual) which is only available since version 4.0. Then it would be

insert into enrolls (section_id,total)
values(324,(SELECT max(sub) FROM enum) +.1);

actually, i don't know if it realy is considered as a subselect, so you can always try it. 'Select into' isn't possible with MySQL

Templeton Peck
06-05-2003, 09:59 PM
here's why that didn't work

insert into enrolls (section_id,total)
values(324,(SELECT max(sub) FROM enrolls) +.1);


its actually trying to call sub from the same table which is against the rules.. any ideas for a work around?

raf
06-06-2003, 08:17 AM
If you edit previous posts, please mark that with <edit> tags or so.

i never had to do anything like that, but i don't see a different option then to break it up in two queryst. First the select, then the insert (or first the insert and then an update)