I don't understand how your column C works...so I'll assume it's pre-known for now. But here's how to get A/B to work.
drop table t if exists; create table t(a int,b int,c int); create trigger trig1 after insert on t begin update t set a=(select count(b) from t where b=new.b) where a=0; end; insert into t values(0,119,0); insert into t values(0,120,1); insert into t values(0,121,0); insert into t values(0,120,2); insert into t values(0,121,2); select * from t; 1|119|0 1|120|1 1|121|0 2|120|2 2|121|2 Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate ________________________________________ From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Tobias Vesterlund [tobias.vesterl...@ericsson.com] Sent: Tuesday, March 29, 2011 6:48 AM To: sqlite-users@sqlite.org Subject: EXT :[sqlite] Generate a unique id unless it is provided Hi, I got a table in my database which looks like the following: A | B | C 1 | 119 | 0 1 | 120 | 1 1 | 121 | 0 2 | 120 | 2 2 | 121 | 2 I want the A value to be generated for the bold rows (ie first inserts of each 'linked' item) and I'd like to re-use the id provided in the other rows. INSERT INTO table VALUES ('',119,0) SELECT TO GET THE AUTO GENERATED VALUE INSERT INTO table VALUES (1,120,1) INSERT INTO table VALUES (1,121,0) Is this possible or should I go with another way of structuring my database? It isn't possible for me to look up the highest value in this database as it will be archived alot (emptied) and I'd like to not have to do check ups in the archive db. Regards, Tobias _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users