lala lala lala lala - 5 months ago 14
MySQL Question

create temporary table in mysql

guys is that possible to use temporary table inside temporary table in mysql ??
as when i use this

CREATE TEMPORARY TABLE bo_attribute_description_group_temp
(SELECT id FROM bo_attribute_description_group WHERE display_name IN ('backoffice.attr.group.services', 'backoffice.attr.group.eyecatchergroup'));


select * from bo_attribute_description_group_temp;


CREATE TEMPORARY TABLE bo_attribute_description_temp (SELECT id FROM bo_attribute_description WHERE group_id IN (bo_attribute_description_group_temp));

but it gives me

0 99 14:17:40

CREATE TEMPORARY TABLE bo_attribute_description_temp (SELECT id
FROM bo_attribute_description
WHERE group_id IN (bo_attribute_description_group_temp)) Error Code: 1054. Unknown column 'bo_attribute_description_group_temp' in 'where clause' 0.000 sec


why ???

Answer

Yes you can. You must use a select clause in the second create table sub-query:

CREATE TEMPORARY TABLE bo_attribute_description_group_temp (SELECT id
                                                        FROM bo_attribute_description_group
                                                        WHERE display_name IN ('backoffice.attr.group.services', 'backoffice.attr.group.eyecatchergroup'));

select * from bo_attribute_description_group_temp;

CREATE TEMPORARY TABLE bo_attribute_description_temp (SELECT id
                                                  FROM bo_attribute_description
                                                  WHERE group_id IN (select id from bo_attribute_description_group_temp));
Comments