I have MainTable with 2 fields: MAIN_ID and DESCRIPTION and SeoncdaryTable with 2 fields: MAIN_ID (FK to MainTable) and EXTRA_INFO.
I would like to have a query that returns one record per MainTable record (select * from MainTable) plus having another result that shows me in comma separated fashion all the records of SecondaryTable (of course matcihing the MAIN_ID).
Moreover I would like in the WHERE condition to be able to filter for SecondaryTable fields.
Example:
MainTable:
MAIN_ID, DESCRIPTION
1, One
2, Two
3, Three
4, Four
Secondary Table
MAIN_ID; EXTRA_INFO;
1; ALPHA
1; BETA
1; GAMMA
3; BETA
4; ALPHA
4; GAMMA
and I want to query all the records where secondary table contains GAMMA, the expected results are
1; One; ALPHA, BETA, GAMMA
4, Four; ALPHA, GAMMA
how to achieve that?
1 Answer