我有这张桌子
conncections
id_user connectedto
1 4
2 4
3 1
1 5
我想做一个SELECT
,它会返回所有与数字1和数字1本身有关系的数字。因此1 4 3 5
为结果。
答案 0 :(得分:1)
像
这样的东西SELECT DISTINCT id_user as related
FROM connections
WHERE connectedto = 1
UNION
SELECT DISTINCT connectedto as related
FROM connections
WHERE id_user = 1
删除UNION副本