I have those tables:
Party
id | date | place
Party_Attendands
id | party_id | person_id | unknow_person_id
Persons
id | name | lastname
I want to denormalize some data and avoid the use of Party_Attendands. Basically I want a view like
Party & PartyPeople
id | date | place | attendands_list
0 | 01/01/2016 | NY | 1,2,3,4
The query below returns the person_ids, but not the unknow_person_ids. People who crashed the party are person too :).
If it's not clear, unknow_person_ids are just ids which are not present in Persons. So each row of Party_Attendands contains a person_id or unknow_person_id but not both.
So attendands_list should contains person_ids and unknow_person_ids, currently handles just the former.
SELECT party.party_id, party.date, attendands.list
FROM party
LEFT OUTER JOIN
(
SELECT party_id , GROUP_CONCAT( Party_Attendands.person_id
ORDER BY person_id
SEPARATOR ',' ) AS list
FROM Party_Attendands
GROUP BY Party_Attendands.party_id
) AS attendands
ON party.party_id = attendands.party_id