mysql-复杂sql

来源:互联网 发布:nba数据网址 编辑:程序博客网 时间:2024/06/01 11:25

将查询结果作为临时表:

select * from (      select a.id as id,b.name as name from t_a a, t_b b where a.id=b.id  ) as tmp  

将查询结果插入到目表表:

  • 表存在
    • insert into 目表表 select * from 表 where 条件
  • 表不存在
    • select * into 目标表 from 表 where 条件

应用:N个表关键查询的结果存到t_new

insert into t_new select * from (      select a.id as id,b.name as name from t_a a, t_b b where a.id=b.id  ) as tmp  
原创粉丝点击