Igor, et al. The first time I posted the question took over 5 hours to get there and back to me. So I assumed that the first question was lost and reposted the question with a small update to reflect the actual problem that wasn't represented in the first case.. My mistake. The 22 is kind of like a time stamp.. (or you could just as easily add another column indicative of a timestamp. insert into stack values (1, 1234); insert into stack values (2, 1234); insert into stack values (6, 1234); insert into stack values (9, 1234); insert into stackpop values (12, 1234) ; insert into stackpop values (14, 1234) ; insert into stackpop values (18, 1234) ; insert into stack values (22, 1234); so that 12 should pop 9, 14 pops 6 and 18 pops 2 leaving the stack with 1 and 22. I haven't had a chance to review your solution. However, I did come up with one of my own for the first case, And a processing solution where the stackpop is queried and the stack table is processed based upon the query results... Solution 1: create temp table t_stack (nid integer primary key autoincrement , id integer, value integer); insert into t_stack (id, value) select * from stack where value = 1234 order by id desc; create temp table t_pop(nid integer primary key autoincrement , id integer, value integer); insert into t_pop (id, value) select * from stackpop order by id asc; select sp.id, s.id from t_pop sp, t_stack s where sp.nid = s.nid; Solution 2: for each row in stackpop sp: 1. stack_pop_id = select max(id) from stack where id < sp.id 2. delete the row from stack where id = stack_pop_id loop Thanks Igor for your suggestions... I agree using sql to implement a stack is pretty bad and maybe the best solution is to do this programatically. Igor Tandetnik <[EMAIL PROTECTED]> wrote: Ken wrote: > Does anyone have ideas on how to implement a stack using sql ???? > Given the following tables and data: > > create table stack( id integer primary key, value integer); > create table stackpop ( id integer primary key, value integer ); > > begin; > insert into stack values (1, 1234); > insert into stack values (2, 1234); > insert into stack values (6, 1234); > insert into stack values (9, 1234); > insert into stack values (22, 1234); > > insert into stackpop values (12, 1234) ; > insert into stackpop values (14, 1234) ; > insert into stackpop values (18, 1234) ; > commit; > > Do you have any ideas for a select that will return the stackpop and > stack id's paired as follows: > 12 | 9 > 14 | 6 > 18 | 2
What's the logic supposed to be here? Why is the stack record with id=22 omitted? I believe I've answered this question the first time you aked it. Have you found the answer lacking? In what respect? Igor Tandetnik ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------