hi again,

i wander in this expression:

****************
* table words      *
* word | number *
****************

insert or replace into words values(bla', coalesce((select count(number)
from words where word = bla)+1, 1));

there is expression:

select count(number) from words where word = bla

which, if i am right, searches through whole table -- i wander is there a
way to use some other function?



Dennis Cote wrote:
> 
> vl.pavlov wrote:
>> 
>> C++ aplication should put words into sqlite3 database, but if word that
>> should be put into the dbase is already in the table of the dbase it
>> should
>> increase the number which is in the second column of the same row. how?
>> 
>> eg:
>> coffee | 3
>> milk | 1
>> 
>> ...
>> 
>> i use standard functions from sqlite3.h
>> 
> 
> You can try this:
> 
> create table words (word text primary key, count integer);
> 
> insert or replace into words values(:word,
>       coalesce((select count from words where word = :word) + 1, 1));
> 
> It will replace the row with a new one that has the count incremented if 
> the word already exists. It will insert the word with a count of 1 if not.
> 
> HTH
> Dennis Cote
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Easy-question-concerning-C%2B%2B---sqlite3-tp15561319p15585117.html
Sent from the SQLite mailing list archive at Nabble.com.

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to