I have an application which keeps a table of daily event counters related to other records in a databse. Since the trackingrecords are kept on a daily basis new records are created each day for items being referenced.

In pseudo-code:

// Check for the existance of daily tracking record
SELECT dailycounterid
FROM dailycounters
WHERE trackingdate = <today>
 AND thingid = <somerecordid>

if <query.recordwasfound>

 // If it exists, increment counter
 UPDATE dailycounters
 SET count = count + 1
 WHERE dailycounterid = <query.dailycounterid>

else

 // Otherwise add new record with count of 1
 INSERT INTO dailycounters
   (trackingdate, thingid, count)
 VALUES
   (<today>, <somerecordid>, 1)

endif


Is there any way to do this with a single MySQL query instead of a check followed by either an insert or an update? The MySQL version is 3.2x using MyISAM tables.




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



Reply via email to