如何在MySQL中将子查询行的结果显示为一列?
我有三个表类别、电影和 RelCatMov
类别表
categoryid, categoryName
1 thriller
2 supsense
3 romantic
4 action
5 sci-fi
电影表
movieid, movieName
1 Avataar
2 Titanic
3 NinjaAssassin
RelCatMov-table
categoryid, MovieID
1 1
2 2
3 2
4 2
5 2
现在我想将记录显示为
MovieName Categories
Titanic Suspense,Romantic,Sci-fi,action
如何做这个。
我正在编写一个查询
select MovieName,(select categoryname from category b,relcatmov c where b.categoryid=c.categoryid and c.movieid=a.movieid) as categories from movies a;
Error: Subquery returns more than one row!!!
如何在一列中显示行的结果?
请帮忙!!!
I have three tables Category, Movies and RelCatMov
Category-table
categoryid, categoryName
1 thriller
2 supsense
3 romantic
4 action
5 sci-fi
Movies-table
movieid, movieName
1 Avataar
2 Titanic
3 NinjaAssassin
RelCatMov-table
categoryid, MovieID
1 1
2 2
3 2
4 2
5 2
Now i Want to display a the record as
MovieName Categories
Titanic Suspense,Romantic,Sci-fi,action
How to do this.
I am writing a query
select MovieName,(select categoryname from category b,relcatmov c where b.categoryid=c.categoryid and c.movieid=a.movieid) as categories from movies a;
Error: Subquery returns more than one row!!!
How to display the result of rows in one column?
Please help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Oracle 中,它称为 stragg。在 MySQL 中它是 GROUP_CONCAT。
作为参考,您的问题是 MySQL 希望您返回单个值,而您却返回了几行。
In Oracle it's called stragg. In MySQL it's GROUP_CONCAT.
For reference, your problem is that MySQL wants you to return a single value and you're returning several rows instead.