How can I simulate an array variable in MySQL?

Well, I’ve been using temporary tables instead of array variables. Not the greatest solution, but it works.

Note that you don’t need to formally define their fields, just create them using a SELECT:

DROP TEMPORARY TABLE IF EXISTS my_temp_table;
CREATE TEMPORARY TABLE my_temp_table
    SELECT first_name FROM people WHERE last_name="Smith";

(See also Create temporary table from select statement without using Create Table.)

Leave a Comment