dtostes :
I have a table in my mysql database that one of the fields create a relation 1 --> N for other table.
My query is:
select
rc.trial_id,
(select label from vocabulary_interventioncode where id = (select interventioncode_id from repository_clinicaltrial_i_code where clinicaltrial_id = rc.id limit 1)) as interventioncode
from
repository_clinicaltrial rc;
i am using:
(select label from vocabulary_interventioncode where id = (select interventioncode_id from repository_clinicaltrial_i_code where clinicaltrial_id = rc.id limit 1))
with limit 1 on the table vocabulary_interventioncode to do not get a error on the query.
Is it possible to concat all the results of the query:
(select label from vocabulary_interventioncode where id = (select interventioncode_id from repository_clinicaltrial_i_code where clinicaltrial_id = rc.id))
and put all the results in a single column ?
Mureinik :
It seems like you're looking for group_concat
:
SELECT rc.trial_id,
GROUP_CONCAT(vi.label)
FROM repository_clinicaltrial rc
JOIN repository_clinicaltrial_i_code rcic ON rcic.clinicaltrial_id = rc.id
JOIN vocabulary_interventioncode vi ON vi.id = rcic.interventioncode_id
GROUP BY rc.trial_id
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=297726&siteId=1