BEGIN;
REPLACE INTO nasdaq_user SELECT CURDATE(),id,status FROM users LEFT JOIN user_cookie ON id=user_id AND invalidated_from IS NULL WHERE status <> 'immune' AND (valid_exchanges & 1) AND cookie_valid_start > CURDATE() AND authorization_expires > now();
REPLACE INTO nasdaq_location SELECT CONCAT(LEFT(CURDATE(),8),"01"),id,nasdaq_location FROM users LEFT JOIN user_cookie ON id=user_id AND invalidated_from IS NULL WHERE status <> 'immune' AND (valid_exchanges & 1) AND cookie_valid_start > CURDATE();
COMMIT;
