由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 菜鸟问题,急
相关主题
sort two same tables SQL but different results请教一个query 优化的问题(filter keyword)
SQL copy a table into a new table and add a new column请教一个SQL的问题
请教一个sql问题请教一个SQL Server的面试题
如何除去duplicate rows?how to write this query
Access 里面两个 column不一样的table 能combine 到一起吗?请问个join的问题
A rookie's query questionerror of sql query in MS Access database (转载)
sql 题目求助sql query help
谁能帮我看看这个Insert语句要怎么改一下?问个sql/ ssis的问题 谢谢!
相关话题的讨论汇总
话题: select话题: newtable话题: table1话题: union话题: table2
进入Database版参与讨论
1 (共1页)
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
1 (共1页)
进入Database版参与讨论
相关主题
问个sql/ ssis的问题 谢谢!Access 里面两个 column不一样的table 能combine 到一起吗?
一个oracle performance 的问题。A rookie's query question
高手请进sql 题目求助
any group function reutrn null if there is null value?谁能帮我看看这个Insert语句要怎么改一下?
sort two same tables SQL but different results请教一个query 优化的问题(filter keyword)
SQL copy a table into a new table and add a new column请教一个SQL的问题
请教一个sql问题请教一个SQL Server的面试题
如何除去duplicate rows?how to write this query
相关话题的讨论汇总
话题: select话题: newtable话题: table1话题: union话题: table2