Query 1
SELECT
`connection`.`person_id`,
`connection`.`follower_id`,
`people`.`name`,
`people`.`age`
FROM
`test`.`people`
INNER JOIN `test`.`connection`
ON (
`people`.`id` = `connection`.`follower_id`
)
WHERE (`connection`.`person_id` = 3);
Query 2
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION GROUP BY person_id
Query 3
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION WHERE (`connection`.`person_id` = 3)
GROUP BY person_id
Query 4
SELECT DISTINCT f.person_id,
o.following,
e.follower
FROM CONNECTION f
LEFT JOIN
(
SELECT CONNECTION.person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS following
FROM CONNECTION GROUP BY person_id
) AS o ON f.person_id = o.person_id
LEFT JOIN
(
SELECT CONNECTION.follower_id, GROUP_CONCAT(DISTINCT person_id SEPARATOR ', ') AS follower
FROM CONNECTION GROUP BY follower_id
) AS e ON f.person_id = e.follower_id