Keiichi McGuire uttered:

I'm a bit stuck on this one problem

I have this simple table that has two fields: id and value.

What I want to do is to get the largest id (the last entry) and then add an
arbitrary number to the value that's in the same entry as that one, and put
the result in the next entry.

to make it sound less confusing, these series of queries should be able to
do a fibbonacci sequence.

I was trying this query and it's not working:
insert into test(value) values((select value from test where id=max(id));

what the heck am I doing wrong?


You can't use aggregate functions in WHERE clauses. Also, you can't use a select as the value in an insert. You can insert from the results of an insert.

The best I could come up with was:
 insert into test (value) select max(id)+value from test;

This sets the value of the new row to the sum of the previous max(id) and it's associated value. But you must have an initial value in the first row.



Thanks!



Christian

--
    /"\
    \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
     X                           - AGAINST MS ATTACHMENTS
    / \

Reply via email to