iT邦幫忙

0

SQL Subquery returns more than 1 row問題

sql

為什麼第二個語法沒寫from emp反而沒有Error

mysql> select ename, sal ,deptno
-> from emp
-> where deptno=(select deptno
-> from emp
-> where ename like '%t%');
ERROR 1242 (21000): Subquery returns more than 1 row

mysql> select ename, sal ,deptno
-> from emp
-> where deptno=(select deptno
-> where ename like '%t%');
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| SMITH | 800.00 | 20 |
| MARTIN | 1250.00 | 30 |
| SCOTT | 3000.00 | 20 |
| TURNER | 1500.00 | 30 |
+--------+---------+--------+
4 rows in set (0.00 sec)

r76021061 iT邦新手 4 級 ‧ 2016-05-22 15:17:45 檢舉
排版歪了我重發....

1 個回答

0
wybeen
iT邦新手 5 級 ‧ 2016-05-23 08:20:23
最佳解答

第二個查詢沒有寫 from 應該就還是 from emp 吧
應該把第一個查詢改成 in

我要發表回答

立即登入回答