I’m attempting to create rows in a temporary table using values from another table as well as static values. The best I could come up with is this snipped of code, using multiple queries. I’m curious if there’s a single SQL query that could achieve this.
CREATE TEMPORARY TABLE temp_users (user_id INT, location_id INT); INSERT INTO temp_users (user_id) SELECT id FROM users WHERE user.role = 'employee'; UPDATE temp_users SET location_id = 11;
Advertisement
Answer
This should work
CREATE TEMP TABLE temp_users AS SELECT id user_id, 11 location_id FROM users WHERE user.role = 'employee';