【发布时间】:2017-08-28 09:26:31
【问题描述】:
我正在尝试插入多行,这些行的值不是取自现有表,而是从外部提供,以及使用 INSERT ... SELECT ... WHERE 的 where 条件。
以下查询无效:
mysql> insert into `my_table` SELECT 1 as a, 2 as b, 3 as c from dual UNION ALL SELECT 4 , 5 , 6 from dual UNION ALL SELECT 7 , 8 , 9 from dual where 1>2 ;
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from my_table;
+---+---+------+
| a | b | c |
+---+---+------+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
+---+---+------+
2 rows in set (0.00 sec)
我想查询不插入任何行,因为where 条件为假。但是,where 子句仅适用于最后一个select,第 2 个selects 不受where 子句的影响。
如何改正?
【问题讨论】:
-
您可以尝试使用 select * from (all your query ) where 1 >2
标签: mysql select sql-insert insert-select