mysql - 在子查询中获取值

标签 mysql sql subquery mysql-error-1064

我不想在结果中使用 r.reguser_id 作为测试列,如果我从 Select 语句中删除此列,那么我在 WHERE bu.business_id = r.reguser_id 中遇到问题 strong> 并收到 More then 1 row Returns.

错误
SELECT r.reguser_name ,  r.reguser_id as test,

(Select r.reguser_id as c, GROUP_CONCAT(i.industry_name) as Industry

From reguser r inner JOIN business_industry bu ON r.reguser_id = bu.business_id  join industry i ON bu.industry_id = i.industry_id

WHERE  bu.business_id = test

GROUP BY bu.business_id
) as indus

FROM reguser r

请告诉我如何解决这个问题? 谢谢。

最佳答案

SELECT r.reguser_name ,  r.reguser_id,

(Select r1.reguser_id as c, GROUP_CONCAT(i.industry_name) as Industry

From reguser r1 inner JOIN business_industry bu ON r1.reguser_id = bu.business_id  join industry i ON bu.industry_id = i.industry_id

WHERE  bu.business_id = r.reguser_id

GROUP BY bu.business_id
) as indus

FROM reguser r

主表和子查询中的表不要使用相同的别名。这确实是不好的做法

关于mysql - 在子查询中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22499919/

相关文章:

mysql - 外键级联更新会传播所有可能的列吗?

mysql - 在 My sql ER 图中创建复合属性?

Python - 如何插入 NULL mysql 值

mysql - Select From 从查询中动态获取的表名

MySQL - 选择有限制的行

mysql - 如何在 MySQL 中使用 ORDER BY FIELD 和子查询?

php - 如何在 Laravel 5 的关系查询中使用 hasRole() 过滤用户?

php - 简单输入/输出记录的复杂选择查询

mysql - 选择所有连接行都匹配的记录

mysql - 从 MySQL 数据库中的数字中删除点和逗号