В Чтв, 30.09.2004, в 00:50, Keith Ivey пишет:
> Aleksandr V. Dyomin wrote:
> 
> >$key='somekeyvalue';
> >dbquery("update sometable set count=count+1 where keyfield='$key'");
> >if(mysql_affected_rows()<1)
> >     dbquery('insert into sometable set keyfield='$key', count=1');
> >
> 
> Another possibility would be
> 
>     INSERT IGNORE INTO sometable SET keyfield = '$key', count = 0;
>     UPDATE sometable SET count = count + 1 WHERE keyfield = '$key';

Not too good method. There is TWO queries ALWAYS, but in my method 1
query for updates(if record exists, which is very often) and two query
for inserts(if record dont exists).
But one question: will this work faster then:
select count(...) as cnt from sometable where keyfield='$key';
...
if($row['cnt']>0)
        update...
else
        insert...

In other words, which method(now 3 known methods) fastes?
1) select -> (insert or update)
2) update -> (insert if fail)
3) ignoring insert -> update
???


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to