我有 3 张桌子:
businesses ( id, name )
categories ( id, name )
business_categories ( business_id, category_id )
第三张桌子是多对多的,PRIMARY KEY
那对有一张。
我正在尝试创建一个类似于以下内容的视图:
business_name category_names
Pizza Hut Restaurants, Pizza, Fast Food
Chipotle Restaurants, Mexican, Fast Food
这是我正在尝试的
SELECT `businesses`.`name`, CONCAT_WS( ',', (
SELECT `name`
FROM `categories`
JOIN `business_categories`
ON `categories`.`id` = `business_categories`.`category_id`
WHERE `business_categories`.`business_id` = `businesses`.`id`
) )
FROM `businesses`
ORDER BY `businesses`.`id` ASC
但我收到此错误:
Subquery returns more than 1 row