Any way to combine the following queries, or some of them? My goal is to achieve faster performance with fewer inserts. However I don't know how to handle the ON DUPLICATE KEY UPDATE new_table.pages=VALUES(pages)
where I will insert more than 2 variables.
mysql_query("INSERT INTO new_table (hash, pages)
SELECT hash, COUNT( id ) AS pages
FROM behaviour GROUP BY hash
ON DUPLICATE KEY UPDATE new_table.pages=VALUES(pages)");
mysql_query("INSERT INTO new_table (hash, visits)
SELECT hash, visits from audience
ON DUPLICATE KEY UPDATE new_table.visits=audience.visits");
mysql_query("INSERT INTO new_table (hash, first_visit)
SELECT hash, timestamp from audience
ON DUPLICATE KEY UPDATE new_table.first_visit=audience.timestamp");
mysql_query("INSERT INTO new_table (hash, last_visit)
SELECT hash, max(timestamp) from behaviour
group by hash
ON DUPLICATE KEY UPDATE new_table.last_visit=VALUES(last_visit)");
mysql_query("INSERT INTO new_table (hash, goals)
SELECT alerts_data_hash, COUNT( * ) AS goals
FROM alerts_data
WHERE alerts_data_status = 'goal'
GROUP BY alerts_data_hash
ON DUPLICATE KEY UPDATE new_table.goals=VALUES(goals)");