What I'd like to do are get results like this:
Code:
AGENCY_NUM | DEFENDANTS
-----------+---------------
2010-66096 | Jones, Smith, Wolfe
Here is my data:
Code:
CASE TABLE
id | agency_num
---+-----------
1 | 2010-44570
2 | 2010-40569
3 | 2010-66096
CASE_RELATIONSHIPS TABLE
case_id | people_id
--------+----------
3 | 15
3 | 16
3 | 23
PEOPLE TABLE
id | last_name
---+----------
15 | Smith
16 | Jones
23 | Wolfe
This is the query I have, but I get an error saying my subquery returns more than one row.
Code:
SELECT agency_num, (SELECT people.last_name FROM people) AS defendants
FROM case LEFT JOIN case_relationships ON case.id = case_relationships.case_id
ORDER BY agency_num
Is this type of query possible? Maybe a subquery is not the right method to do this. Thanks!