avatar
菜鸟问题,急# Database - 数据库
M*7
1
请问下面这个QUERY为什么不WORK
SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)
括号里的QUERY单独可以work。这里我如果想加order by 的话可以吗?
谢谢
avatar
n*6
2
SELECT COL1, COL2
INTO Newtable
FROM Table1
Prerequirement: Newtable does not exist. The process will automatic create
the new table.
I do not know if you can use
(SELECT * FROM Table1
UNION ALL
SELECT * FROM Table2)
INTO NewTable

【在 M***7 的大作中提到】
: 请问下面这个QUERY为什么不WORK
: SELECT *
: INTO NewTable
: FROM ( SELECT COL1,COL2 FROM Table1
: UNION ALL
: SELECT COL3,COL4 FROM Table2)
: 括号里的QUERY单独可以work。这里我如果想加order by 的话可以吗?
: 谢谢

avatar
B*g
3
CREATE TABLE NewTable AS
SELECT *
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)
or
INSERT INTO NewTable
SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)

【在 M***7 的大作中提到】
: 请问下面这个QUERY为什么不WORK
: SELECT *
: INTO NewTable
: FROM ( SELECT COL1,COL2 FROM Table1
: UNION ALL
: SELECT COL3,COL4 FROM Table2)
: 括号里的QUERY单独可以work。这里我如果想加order by 的话可以吗?
: 谢谢

avatar
M*7
4
guys, thanks a lot .
Finally I used the following query
=====================
INSERT INTO NewTalbe
SELECT col1, col2 FROM TABLE1
UNION ALL
SELECT col3 col4 FROM TABLE2
======================
It woks.
If I use
=================
CREATE TABLE newtable AS
SELECT *
FROM (SELECT col1, col2 FROM TABLE1
UNION ALL
SELECT col3 col4 FROM TABLE2)
===================
It still did not work.
Could anyone explain it a little bit detail for me? I am really a rookie in
SQL.
Thanks.
avatar
B*g
5
Create one will work if
1. you user oracle
2. NewTable does not exists

【在 M***7 的大作中提到】
: guys, thanks a lot .
: Finally I used the following query
: =====================
: INSERT INTO NewTalbe
: SELECT col1, col2 FROM TABLE1
: UNION ALL
: SELECT col3 col4 FROM TABLE2
: ======================
: It woks.
: If I use

avatar
b*e
6
Try this one. Just add a alias name.
SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2) a
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。