I have a question about a MySQL query. I would (obviously) like to use as few queries as possible for this, and hopefully just one. What I’m trying to do is update a column in the database if the info is different.
For example, say I have the column “referer” and the column “date”. If the user clicks the link and the referer is different but the date is the same, I would like to update only the referer column.
This is my current query:
mysql_query ("
UPDATE clicks
SET
clicks = clicks + 1
, referers = CONCAT(referers, ',$referer')
, dates = CONCAT(dates, ',$date')
WHERE shortURL = '$url'
AND referer != $referer
");
Is there any way to work this into one query?
You should read something about database normalization.
first normalization rule is: fields have to be atomic. in your case: don’t save multiple referers/dates into one field separated by commas.