Just learning about sql joins and things, and I have a question.
Can you JOIN on an update query? Or is it only for select ones. Because I have this code;
$five_ago = date("Y-m-d H:i:s", strtotime("$now - 5 mins"));
$sql_result23 = mysql_query("SELECT * FROM usersonline WHERE timestamp < '$five_ago'", $db);
while ($rs23 = mysql_fetch_array($sql_result23)) {
mysql_query("UPDATE users SET status='gone' WHERE id ='$rs23[userID]'");
}
It picks out from the usersonline table all the ones that are older than 5 minutes, then finds them in the users table and updates their record.
I’m not a JOIN wizard or anything but i think a join would simplify that.
Can someone clarify this?
Using
IN:Using
JOIN:Using
EXISTS:You could also skip the
5 minutes agocalculations in PHP and let the MySQL engine do that work, with: