简体   繁体   English

MySQL-多个内部联接和concat

[英]MySQL - Multiple inner joins and concat

I have a database, here are the tables I need: 我有一个数据库,这是我需要的表:

  • special_issues 特刊
  • journals 期刊
  • journal_editors journal_editors

The structure is like described here: 结构如下所示:

  • I have special issues, each special issue belongs to a journal, so in the table special_issue, I have the journal_id 我有特刊,每个特刊都属于一个日记,因此在表special_issue中,我有journal_id
  • For each journal, I have editors (one or more). 对于每本期刊,我都有编辑(一个或多个)。 This info can be obtained from the journal_editors table by matching the editors for the specific journal_id. 通过匹配特定journal_id的编辑者,可以从journal_editors表中获取此信息。

What I would like to get is for each special issue, the journal editors of the journal this special issue belongs. 我想获得的是每本特刊,该特刊所属期刊的期刊编辑。

For that, I would like to concat the id's, so at the end I will have something like this: 为此,我想连接ID,因此最后我将得到以下内容:

special issue    editors
     si1         1,5,10
     si2         14,25,5 

Etc... 等等...

I tryied that: 我试了一下:

SELECT si.name, CONCAT(users.firstname,' ', users.lastname) AS journal_editors
FROM `special_issues` si
INNER JOIN journal_editors jeds ON si.journal_id = journal_id
WHERE si.journal_id =1 GROUP BY si.name"

Thank you very much in advance. 提前非常感谢您。

SELECT si.name, GROUP_CONCAT(users.firstname,' ', users.lastname) AS journal_editors 
FROM special_issues si 
INNER JOIN journal_editors jeds ON si.journal_id = journal_id 
WHERE si.journal_id =1 
GROUP BY si.name

Manual entry . 手动输入

SELECT si.name, GROUP_CONCAT(users.firstname,' ', users.lastname) AS journal_editors
  FROM `special_issues` si
 INNER 
  JOIN journal_editors jeds ON si.journal_id = jeds.journal_id
 WHERE si.journal_id =1 
 GROUP BY si.name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM