I have the query, below, which should work. But, MySQL is giving me the error message
Subquery returns more than one row
SELECT e.episode_pk,
(SELECT GROUP_CONCAT(d.fulldescription separator ', ')
FROM episode_rhythm er
JOIN diagnosis d ON er.diagnosis_fk = d.diagnosis_pk
WHERE er.episode_fk = e.episode_pk
GROUP BY d.fulldescription) as rhythmDesc
FROM episode e
WHERE e.patientid_fk = '89976';
The entire purpose of using the GROUP_CONCAT
in this query is to return only one row per 'episode'.
The outer select returns multiple rows.
The inner SELECT
, when run for a single episode table primary key, returns a single row as you would suspect:
SELECT group_concat(d.fulldescription separator ', ')
FROM episode_rhythm er
JOIN diagnosis d ON er.diagnosis_fk = d.diagnosis_pk
WHERE er.episode_fk = 234776
GROUP BY d.fulldescription;
The inner SELECT
without the GROUP_CONCAT
, when run for a single episode table primary key, may return multiple rows:
SELECT d.fulldescription
FROM episode_rhythm er
JOIN diagnosis d ON er.diagnosis_fk = d.diagnosis_pk
WHERE er.episode_fk = 234776;
What do I need to do to get this to work as I would expect?