MySQL使用Union创建视图报错


mysql>  select  from  test_main;
+ ----+-------+
| id | value |
+ ----+-------+
|  1 | ONE   |
|  2 | TWO   |
|  3 | THREE |
+ ----+-------+
rows  in  set  (0.00 sec)
 
mysql>  create  table  test_main2  select  from  test_main;
Query OK, 3  rows  affected (0.04 sec)
Records: 3  Duplicates: 0  Warnings: 0
 
 
-- 创建视图, sql 语句加了括号, 报错。
CREATE  VIEW  view_test_main
AS
(
SELECT  FROM  test_main
UNION  ALL
SELECT  FROM  test_main2
);
 
ERROR 1064 (42000): You have an error  in  your SQL syntax;  check  the manual that
corresponds  to  your MySQL server version  for  the  right  syntax  to  use near  'UNION
  ALL
SELECT * FROM test_main2
)'  at  line 5
 
 
 
-- 创建视图, sql 语句不加括号, 通过。
mysql>  CREATE  VIEW  view_test_main
     ->  AS
     ->  SELECT  FROM  test_main
     ->  UNION  ALL
     ->  SELECT  FROM  test_main2;
Query OK, 0  rows  affected (0.01 sec)







免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM