If you have a unique index on name, you could use INSERT OR IGNORE. https://www.sqlite.org/lang_conflict.html
INSERT OR IGNORE INTO TAGS (NAME, COUNT) VALUES ('Bleh', 1) As for your original query: think about just the select clause (you can run it independently). This will return ('magnetohydrodynamics', 1) for each row in the table. If you did not want to use INSERT OR IGNORE, you could put a LIMIT 1 in there, or rephrase your query to not use TAGS in the outer select (note: you never actually reference anything in the TAGS specified in the outer select) > On 15 Sep 2015, at 1:06 pm, Nicolas J?ger <jager.nicolas at laposte.net> > wrote: > > hi, > I have a table TAGS with idkey and two colums (NAME, COUNT): > > id|NAME|COUNT > 53|black metal|3 > 55|occult rock|3 > 61|satanic smurfs|1 > 62|beer|0 > 63|pizza|0 > > I want to check if some tag exist by checking if `NAME` is recorded > in the table or not. If not, I want to add it; > > INSERT INTO TAGS ( NAME, COUNT ) SELECT 'magnetohydrodynamics', 1 > FROM TAGS WHERE NOT EXISTS (SELECT * FROM TAGS WHERE NAME = > 'magnetohydrodynamics' ); > > then if I look up in the table I see: > > id|NAME|COUNT > 53|black metal|3 > 55|occult rock|3 > 61|satanic smurfs|1 > 62|beer|0 > 63|pizza|0 > 64|magnetohydrodynamics|1 > 65|magnetohydrodynamics|1 > 66|magnetohydrodynamics|1 > 67|magnetohydrodynamics|1 > 68|magnetohydrodynamics|1 > > could you tell me please where I did some mess ? > > regards, > Nicolas J. > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users