Is there any way to insert rows into a temporary table after creating it via SELECT
statement in MySQL?
I have this query that works as expected:
SELECT goldusers_user_ci.user_id, goldusers_users.username, goldusers_user_ci.contact_value
FROM goldusers_users
INNER JOIN goldusers_user_ci
ON goldusers_users.id = goldusers_user_ci.user_id
ORDER BY user_id
The idea is to select this query as a temporary table and add one row to it, like so:
SELECT * FROM(
SELECT goldusers_user_ci.user_id, goldusers_users.username, goldusers_user_ci.contact_value
FROM goldusers_users
INNER JOIN goldusers_user_ci
ON goldusers_users.id = goldusers_user_ci.user_id
ORDER BY user_id
) AS DBusers
INSERT INTO DBusers(user_id,username)
VALUES(-1,"All")
However, I get a syntax error. Is there any way to do this?
**Edit:
I believe I actually need to do a union after the select:
***the issue is the placement of the ORDER BY
statement. Moving it to the bottom works
SELECT goldusers_user_ci.user_id, goldusers_users.username, goldusers_user_ci.contact_value
FROM goldusers_users
INNER JOIN goldusers_user_ci
ON goldusers_users.id = goldusers_user_ci.user_id
UNION ALL
SELECT -1 as user_id, "All" as username, "" as contact_value
ORDER BY user_id