mysql将表a中查询的数据插入到表b中
如果表b存在
1
<code class=sql><code class=sql><code class=sql>insert into b select * from a;</code></code></code>
如果表b不存在
1
<code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql>create table b as select * from a;</code></code></code></code></code></code>
扩展:
将b表中的某写字段值插入到a表中
1
<code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql>insert into a (userid,username) select b.userid,b.username from tr_ajax_chat_messages;</code></code></code></code></code></code></code></code></code></code></code>
将a表和b表userid相等的值保存到a表
1<code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql><code class=sql>update a set a.username=(select b.username from b where a.userid = b.userid);</code></code></code></code></code></code></code></code></code></code></code></code></code></code></code></code></code></code>,
中国足彩网信息请查看IT技术专栏