¹Ú Çö±Ù wrote: > Hi...! > > I am developing with SQLite in these days but I am having problem creating > auto_increment ID. > I looked at FAQ section, but I couldn't find the solution. > I am using sqlite 3.08 at the moment. > > Here is the sample statement: > > sqlite>create table fruits (id int primary key, name varchar(50)); > sqlite>create table temp (id int primary key, type int, name varchar(50)); > sqlite>insert into temp values (1, 0, 'apple'); > sqlite>insert into temp values (2, 0, 'orange'); > sqlite>insert into temp values (3, 1, 'potato'); > sqlite>insert into temp values (4, 1, 'onion'); > sqlite>insert into temp values (5, 0, 'banana'); > > I want to insert the rows whose type is fruits(=1) in kinds of temp table > into fruits table. > > sqlite>insert into fruits select ifnull((select max(id) from fruits), 0)+1, > name from temp where type = 1; >
Does this do what you want? sqlite> insert into fruits select temp.id, temp.name from temp where temp.type = 1; sqlite> select * from fruits; 3|potato 4|onion Gerry Snyder