On Sun, Apr 3, 2011 at 3:49 AM, Marcelo S Zanetti <mszane...@yahoo.com> wrote: > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT itemID from tabel WHERE item==new ELSE > INSERT INTO table (item) VALUES (new)
INSERT INTO t (item) SELECT :new WHERE NOT EXISTS (SELECT item FROM t WHERE item = :new); Here :new is a parameter to be bound with sqlite3_bind_*(). Of course, it also seems like you could just INSERT OR IGNORE, as it seems likely that you want that item column to be a unique key (if not the primary key). There's no IF in SQL, and you can't embed an INSERT/UPDATE/DELETE inside a SELECT (so CASE won't help). But you _can_ have WHERE clauses that don't obviously relate to the rows being selected. Nico -- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users