MySQL____将查询结果插入到表中

insert与select的嵌套使用的方法

下面select的数据封装成了视图?然后将其数据插入到exchangeinfo表中

INSERT INTO wc_exchangeinfo(exchangeid2,exchangeid) SELECT * FROM (SELECT wc_exchange.id,wc_exchangeinfo.exchangeid FROM wc_exchange LEFT JOIN wc_exchangeinfo ON wc_exchange.id=wc_exchangeinfo.exchangeid)AS a


试验后发现直接将查询结果插入也可以
INSERT INTO wc_exchangeinfo(exchangeid2,exchangeid) SELECT wc_exchange.id,wc_exchangeinfo.exchangeid FROM wc_exchange LEFT JOIN wc_exchangeinfo ON wc_exchange.id=wc_exchangeinfo.exchangeid


试验后发现,每一个派生出的新表都必须指定别名才可以。否则报错:Every derived table must have its own alias


你可能感兴趣的:(MySql)