This is part of a series of quick tips and tricks I have accumulated over the year, that I think can be useful for others.
If you have similar short tips and tricks please leave a comment.
When testing your code you may need a range on integers and the trick for generating such a range is to use a local variable that you increment by one for each row.
In the code below we are using the information_schema.COLUMNS table, so be aware that this specific query will only generate a maximum of numbers that is the the same as the information_schema.COLUMNS table, but you can use any one of your table to get the same effect.
You have to do something slightly different to generate a range of int on the
CREATE OR REPLACE TEMPORARY TABLE int_range (num int);
SET @range_limit = 24;
INSERT INTO int_range
SELECT @rownum := @rownum + 1
FROM information_schema.COLUMNS C, (SELECT @rownum := 0) r
WHERE @rownum < @range_limit;