MySQL
- 3 ответа
- 0 вопросов
1
Вклад в тег
CREATE TABLE `frends` (
`from_user_id` INT(11) NULL DEFAULT NULL,
`to_user_id` INT(11) NULL DEFAULT NULL
);
INSERT INTO `frends` (`from_user_id`, `to_user_id`) VALUES
(1, 3),
(3, 1),
(1, 2),
(1, 4),
(4, 1),
(3, 4),
(5, 1),
(5, 4),
(4, 5),
(1, 5);
select frends.from_user_id 'Я', group_concat(frendsPlus.from_user_id) 'Мы друзья'
from frends
left join frends frendsPlus on
(
frends.from_user_id = frendsPlus.to_user_id and
frendsPlus.from_user_id = frends.to_user_id
)
group by frends.from_user_id