hessodreamy
Programmer
I need to keep a running count of actions for particular dates, so I need to say 'if this date & value aren't in the table, insert them. if they are, increment them'. Is this possible to do in 1 query? I can't figure how.
Here's what I'm doing at the minute:
if the result is 0, then insert it:
otherwise increment:
This seems pretty inefficient to me. Can it be done in one query? btw i'm using version 4.0
Here's what I'm doing at the minute:
Code:
SELECT count(*) FROM tracking WHERE date = current_date() AND source = 'somesource' AND target = 'sometarget'
Code:
INSERT INTO tracking (`source`,`target`, `hits`, `date`)
VALUES ('somesource', 'sometarget', 1, current_date())
Code:
UPDATE tracking set hits = hits + 1 WHERE `source` = 'somesource' AND `target`='sometarget' AND date = current_date()
This seems pretty inefficient to me. Can it be done in one query? btw i'm using version 4.0