如何将 MySQL 查询结果存储在另一个表中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2698401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:52:12  来源:igfitidea点击:

How to store MySQL query results in another Table?

mysqlsqldatabase

提问by Tasawer Khan

How to store results from following query into another table. Considering there is an appropriate table already created.

如何将以下查询的结果存储到另一个表中。考虑到已经创建了一个合适的表。

SELECT labels.label,shortabstracts.ShortAbstract,images.LinkToImage,types.Type
FROM ner.images,ner.labels,ner.shortabstracts,ner.types
WHERE
  labels.Resource=images.Resource
  AND labels.Resource=shortabstracts.Resource
  AND labels.Resource=types.Resource;

回答by phatrick

If the table doesn't exist (and you e.g. don't want to create it because it may have lots of column names) you can create it on the fly...

如果该表不存在(例如您不想创建它,因为它可能有很多列名),您可以即时创建它...

Query:

询问:

CREATE TABLE another_table SELECT /* your query goes here */

回答by codaddict

You can use the INSERT INTO TABLE SELECT....syntax:

您可以使用INSERT INTO TABLE SELECT.... 语法:

INSERT INTO new_table_name
SELECT labels.label,shortabstracts.ShortAbstract,images.LinkToImage,types.Type 
FROM ner.images,ner.labels,ner.shortabstracts,ner.types 
WHERE labels.Resource=images.Resource AND labels.Resource=shortabstracts.Resource 
AND labels.Resource=types.Resource;

回答by tarikul05

if your table dosen't exist then

如果你的表不存在那么

CREATE TABLE new_table SELECT //write your query here

if your table exist then you can just insert query

如果您的表存在,那么您可以插入查询

INSERT INTO new_table SELECT //write your query here

For more check hereand here

有关更多信息,请查看此处此处

回答by Your Common Sense

INSERT INTO another_table SELECT /*your query goes here*/