When working on very large tables, you may occasionally need to run many queries to get a small subset of a large amount of data. Instead of running these queries against the entire table, let MySQL find the few records it needs at a time, putting It may be faster to select records into a temporary table and then run the query on those tables.
Creating a temporary table is easy by adding the TEMPORARY keyword to the normal CREATE TABLE statement:
CREATE TEMPORARY TABLE tmp_table ( name VARCHAR(10) NOT NULL, value INTEGER NOT NULL )