select a.*,(select count(id) as d from comment2 where a.id=articleId),(select max(id) as b,max(name) as e from comment2 where a.id=articleId) from article as a where a.classId=1 这是我的SQL语句。。运行时报Operand should contain 1 column(s)但是如果独立运行select max(id) as b,max(name) as e from comment2 where 1=articleId 就不会报错。。请高手帮忙解决一下。。
(select count(id) as d from comment2 where a.id=articleId),
(select max(id) as b from comment2 where a.id=articleId) as b ,
(select max(name) as e from comment2 where a.id=articleId) as e
from article as a where a.classId=1
子查询只能返回一列
select a.*,
(select count(id) as d from comment2 where a.id=articleId),
(select max(id) as b from comment2 where a.id=articleId) ,
(select max(name) as e from comment2 where a.id=articleId)
from article as a where a.classId=1 可以优化一下SQL语句
+-------------+---------------+
| max(userid) | max(username) |
+-------------+---------------+
| 9 | 譏ッ蠕キ蝗ス |
+-------------+---------------+
1 row in set (0.02 sec)
mysql> select * ,(select max(userid),max(username) from user) from user;
ERROR 1241 (21000): Operand should contain 1 column(s)
er) t;
+--------+--------------------+------+-----------+------+-----------+
| userid | username | a | b | a | b |
+--------+--------------------+------+-----------+------+-----------+
| 1 | aaaaaaaaaaaaaaaaaa | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 2 | 螟ァ譏ッ荳ェ | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 3 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 4 | | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 5 | 莠懶ス難ス・ | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 6 | 螢ォ螟ァ螟ォ | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 7 | d | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 8 | 螳俶婿 | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
| 9 | ? | 9 | 譏ッ蠕キ蝗ス | 9 | 譏ッ蠕キ蝗ス |
+--------+--------------------+------+-----------+------+-----------+
9 rows in set (0.00 sec)
可以参考这个 写道from 后