SQLITE Query results into a temp table

爷,独闯天下 提交于 2019-12-09 06:20:35

问题


I haven't used SQLite before and can't figure out the syntax, I have this working in SQL Server if it helps.

I need to put the results into a temp table so I can reuse them.

//SQL Server

WITH FT_CTE AS
(
SELECT pID, cID FROM brFTNode_Children 
WHERE pID = 1
UNION ALL
    SELECT e.pID, e.cID FROM brFTNode_Children e
    INNER JOIN FT_CTE ftCTE on (ftCTE.cID = e.pID)
)
SELECT * INTO #ParentChild FROM FT_CTE;

//SQLite try

WITH FT_CTE AS
(
SELECT pID, cID FROM brFTNode_Children 
WHERE pID = 1
UNION ALL
    SELECT e.pID, e.cID FROM brFTNode_Children e
    INNER JOIN FT_CTE ftCTE on (ftCTE.cID = e.pID)
)
CREATE TEMPORARY TABLE ParentChild as SELECT * FROM FT_CTE;

I get Error near "CREATE": syntax error


回答1:


The CREATE TABLE statement does not allow CTEs, but the SELECT does:

CREATE TEMPORARY TABLE ParentChild AS
WITH FT_CTE AS (
    SELECT pID, cID FROM brFTNode_Children 
    WHERE pID = 1
    UNION ALL
    SELECT e.pID, e.cID FROM brFTNode_Children e
    INNER JOIN FT_CTE ftCTE ON (ftCTE.cID = e.pID)
)
SELECT * FROM FT_CTE;


来源:https://stackoverflow.com/questions/26491230/sqlite-query-results-into-a-temp-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!