访问别名表 [英] Accessing aliased tables

查看:73
本文介绍了访问别名表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是错误的.我对工会的运作方式有很大的误解.我正在阅读有关它.

This question is wrong. I had some very big misunderstanding about how union works. I am reading about it now.

编辑04.12.2016 如果您仍然有兴趣,可以去这里 选择右列

edit 04.12.2016 If you are still intersted, you can go here Selecting the right column

我有这样的东西

with table3 as
(
  select t1.c1, t1.c2...
  from table1 t1
  union all
  select t2.c1, t2.c2...
  from table2 t2
)select * from table3

我需要从上方将所有行插入另一个表

I need to insert all rows from above in another table

insert into table4 t4
(
  t4.c1, t4.c2...
)
select t3.c1, t3.c2...
from table3 t3 

我的问题是,此插入能否正常工作.表1和表2中有相同的名称,是否需要以不同的方式引用它们?

My question is, will this insert work. I have clumns in table 1 and 2 named the same, will I need to reference them somehow differently?

我需要这样写吗?

insert into table4 t4
    (
      t4.c1, t4.c2...
    )
    select t3.t1.c1, t3.t1.c2, t3.t2.c1...
    from table3 t3 

推荐答案

无需别名

如果列匹配,则只需使用插入选择

if the column match you could simply use insert select

insert into table4 
( select t1.c1, t1.c2...
  from table1 t1
  union all
  select t2.c1, t2.c2...
  from table2 t2) 

否则,您应该声明列名

insert insert into table4(c1, c2... )
( select t1.c1, t1.c2...
  from table1 t1
  union all
  select t2.c1, t2.c2...
  from table2 t2) 

这篇关于访问别名表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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