Code: Select all
$users = mysql_query ("SELECT * FROM wqw_users");
$all = mysql_fetch_assoc ($users);
$delete = mysql_query ("DELETE FROM wqw_items WHERE userid! =". $all ['id']."");Moderator: General Moderators
Code: Select all
$users = mysql_query ("SELECT * FROM wqw_users");
$all = mysql_fetch_assoc ($users);
$delete = mysql_query ("DELETE FROM wqw_items WHERE userid! =". $all ['id']."");Code: Select all
DELETE FROM `wqw_items` WHERE userid NOT IN (SELECT `id` FROM `wqw_users`);I wouldn't recommend using that query, as it will load the entire users table.twinedev wrote:Use this query:
Code: Select all
DELETE FROM `wqw_items` WHERE userid NOT IN (SELECT `id` FROM `wqw_users`);
Code: Select all
DELETE FROM wqw_items AS item
LEFT JOIN wqw_users AS user ON item.userid = user.id
WHERE item.userid IS NULL