How can I store the output of a query into a temporary table and use the table in a new query?

守給你的承諾、 提交于 2019-12-04 14:46:20

This is very straightforward:

CREATE TEMPORARY TABLE tempname  AS (    
    SELECT whatever, whatever
      FROM rawtable
      JOIN othertable ON this = that
)

The temporary table will vanish when your connection closes. A temp table contains the data that was captured at the time it was created.

You can also create a view, like so.

CREATE VIEW viewname AS (    
    SELECT whatever, whatever
      FROM rawtable
      JOIN othertable ON this = that
)

Views are permanent objects (they don't vanish when your connection closes) but they retrieve data from the underlying tables at the time you invoke them.

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