[英]Mysql SELECT for friends system
I have this table 我有这张桌子
conncections
id_user connectedto
1 4
2 4
3 1
1 5
i would like to do a SELECT
that gives me back all the numbers that have a relation with the number 1 and the number 1 itself. 我想进行一次
SELECT
,将所有与数字1和数字1本身相关的数字退还给我。 Therefore 1 4 3 5
as result. 因此,结果为
1 4 3 5
。
Something like 就像是
SELECT DISTINCT id_user as related
FROM connections
WHERE connectedto = 1
UNION
SELECT DISTINCT connectedto as related
FROM connections
WHERE id_user = 1
With UNION duplicate are removed 与UNION一起删除重复项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.