CREATE TABLE IT1 ( name VARCHAR(64), roll_no INTEGER )
CREATE TABLE IT2 ( name VARCHAR(64), roll_no INTEGER )
CREATE TABLE IT3 ( name VARCHAR(64), roll_no INTEGER )
INSERT INTO IT1 (name, roll_no) VALUES ('aa','13')
INSERT INTO IT2 (name, roll_no) VALUES ('bb','10')
INSERT INTO IT3 (name, roll_no) VALUES ('cc','78')
SELECT *
INTO Student
FROM ( SELECT
IT1.name, IT1.roll_no
FROM IT1
UNION
SELECT
IT2.name,IT2.roll_no
FROM IT2
UNION
SELECT
IT3.name,IT3.roll_no
FROM IT3
) n
ORDER BY roll_no ASC
答案 0 :(得分:1)
MySQL不支持SELECT ... INTO ...
语法。
您必须使用INSERT INTO ... SELECT ..
语法才能完成此任务。
在此处阅读更多内容.. http://dev.mysql.com/doc/refman/5.0/en/insert-select.html
试试这个
CREATE TABLE IT1 ( name VARCHAR(64), roll_no INTEGER );
CREATE TABLE IT2 ( name VARCHAR(64), roll_no INTEGER );
CREATE TABLE IT3 ( name VARCHAR(64), roll_no INTEGER );
INSERT INTO IT1 (name, roll_no) VALUES ('aa','13');
INSERT INTO IT2 (name, roll_no) VALUES ('bb','10');
INSERT INTO IT3 (name, roll_no) VALUES ('cc','78');
CREATE table student as SELECT *
FROM
(SELECT IT1.name,
IT1.roll_no
FROM IT1
UNION SELECT IT2.name,
IT2.roll_no
FROM IT2
UNION SELECT IT3.name,
IT3.roll_no
FROM IT3) n
ORDER BY roll_no ASC
答案 1 :(得分:0)
首先创建学生表..尝试下面
CREATE table student as SELECT *
FROM
(SELECT IT1.name,
IT1.roll_no
FROM IT1
UNION SELECT IT2.name,
IT2.roll_no
FROM IT2
UNION SELECT IT3.name,
IT3.roll_no
FROM IT3) n
ORDER BY roll_no ASC