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.
// Check for the existance of daily tracking record
WHERE trackingdate = <today>
AND thingid = <somerecordid>
// If it exists, increment counter
SET count = count + 1
WHERE dailycounterid = <query.dailycounterid>
// Otherwise add new record with count of 1
INSERT INTO dailycounters
(trackingdate, thingid, count)
(<today>, <somerecordid>, 1)
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.