有一个表,名字是main,表内容如下:mysql>select*frommain;+------+----------+|ID|username|+------+----------+|0|user0||1|user1||2|user2|+------+----------+执行命令返回:mys... 有一个表,名字是main,表内容如下:mysql> select * from main;+------+----------+| ID | username |+------+----------+| 0 | user0 || 1 | user1 || 2 | user2 |+------+----------+执行命令返回:mysql> select username from main where username='user0' || (select 1 from dual where (select username from main where username='user0')='user0');+----------+| username |+----------+| user0 || user1 || user2 |+----------+为什么会有这个结果?我从来没有在我的语句里面涉及user1和user2,顺便说一下,单独执行执行第二句select 1 from dual where (select username from main where username='user0')='user0'结果如下:+---+| 1 |+---+| 1 |+---+ 展开
1 回答
鸿蒙传说
TA贡献1865条经验 获得超7个赞
mysql> select username from main where username='user0' || (select 1 from dual where (select username from main where username='user0')='user0');
+----------+
| username |
+----------+
| user0 |
| user1 |
| user2 |
+----------+
那个||是连接字符串,是Oracle 里面连接字符串的。
MySQL 里面, 连接字符串是用 CONCAT 函数来连接的。
如果你要连接字符串,那么
='user0' || (select 1 from ..... )
需要修改为=CONCAT('user0',(select1from.....))
添加回答
举报
0/150
提交
取消