mysql优化 - MySQL语句优先级问题,如IN后面的子句似乎必须要带小括号,有时候多了小括号又出错?
怪我咯
怪我咯 2017-04-17 11:53:33
[MySQL讨论组]
mysqlmysql> select c from tb8 where c in select b from tb6;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
sponds to your MySQL server version for the right syntax to use near 'select b from t
b6' at line 1
mysql> select c from tb8 where c in (select b from tb6);
+------+
| c    |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)
sqlmysql> insert into tb11 (select * from tb6);
Query OK, 2 rows affected (0.07 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into tb11 (select * from tb6) union (select * from tb7);
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0

--下面这句有疑问
mysql> insert into tb11 (select * from tb6 union select * from tb7);
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 select * from tb7)' at line 1

mysql> insert into tb11 select * from tb6 union select * from tb7;
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0

如c++很容易通过{, }来分辨一段代码的层次,MySQL感觉有些杂乱,不知道有何诀窍。

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
PHPz

可以加一些回车来区分,只要不遇到;就不算结束。所以上句可以改写为:

insert into tb11
select * from tb6
union select * from tb7;

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号