从一个表中选择并插入到另一个表中 [英] select from one table and insert into another

查看:72
本文介绍了从一个表中选择并插入到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个桌子.

Table_A(nid,vid,类型,标题,uid)

Table_A (nid, vid, type, title, uid)

Table_B(id,问题文本)

Table_B (id, questiontext)

我需要将Table_B中的记录插入Table_A中.我试过了:

I need to insert records from Table_B into Table_A. I tried this:

INSERT INTO Table_A (nid, vid, type, title, uid)
VALUES ('', '', multichoice', (SELECT questiontext from Table_B), '1')

但是它抛出一个错误.

正确的陈述应该是什么?

What should be the correct statement?

UPD:我应该补充一点,nid是自动递增的,并且vid的值应与nid相同.

UPD: I should add that nid is autoincrement and the value of vid should be same as nid.

推荐答案

您尝试过

INSERT INTO Table_A (nid, vid, type, title, uid) 
SELECT  '', 
        '', 
        'multichoice', 
        questiontext ,
        '1'
from    Table_B

看看插入...选择语法

这篇关于从一个表中选择并插入到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆