2016-07-02 138 views
-2

是不是可以在臨時表裏面使用臨時表? 當我使用在mysql中創建臨時表

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) 
); 

,但它給了我

Error Code: 1054. Unknown column 'bo_attribute_description_group_temp' in 'where clause' 0.000 sec 

爲什麼???

回答

0

是的,你可以。您必須在第二個創建表子查詢中使用select子句:

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)); 
+0

它沒有工作或者 –

+0

什麼是錯誤消息? –