M***7 发帖数: 2420 | 1 请问下面这个QUERY为什么不WORK
SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)
括号里的QUERY单独可以work。这里我如果想加order by 的话可以吗?
谢谢 | n********6 发帖数: 1511 | 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 的话可以吗? : 谢谢
| B*****g 发帖数: 34098 | 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 的话可以吗? : 谢谢
| M***7 发帖数: 2420 | 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. | B*****g 发帖数: 34098 | 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
| b*****e 发帖数: 364 | 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 |
|