Using Temporary Tables

Utilizing temporary tables allows you to store interim results within a report and process them further. Temporary tables are connection-based, ensuring that different users using temporary tables with the same name do not conflict.

delimiter 
$$
drop procedure if exists sp_DBR_fruits
$$
create procedure sp_DBR_fruits()
begin

drop temporary table if exists fruits_tmp;
create temporary table fruits_tmp ( fruit varchar(30) ):

insert into fruits_tmp (fruit)
select 'banana'
union
select 'orange'
union
select 'lemon';

insert into fruits_tmp (fruit) 
values( 'apple' );

select count(*) as 'fruits' from fruits_tmp;
drop temporary table fruits_tmp;

end
$$
CALL sp_DBR_fruits();
+--------+
| Fruits |
+--------+
|      4 | 
+--------+
1 row in set (0.00 sec)