我试过这个
Select u from users where idU in
((Select idU1 from friends where idU2=1) Union (Select idU2 from friends where idU1=1))
但它不起作用。
所以,我必须这样做:
Select u from users where idU in (Select idU1 from friends where idU2=1)
Union
Select u from users where idU in (Select idU2 from friends where idU1=1)
但是现在,我想通过上次登录来订购这些用户。
我该怎么办? TY。
答案 0 :(得分:0)
尝试如下。
我写这篇文章时要记住LastLogin
列在用户表
Select
u
from
users
where
idU in (
Select idU1 from amistades where idU2 = 1
Union
Select idU2 from friends where idU1 = 1
)
ORDER BY LastLogin;
答案 1 :(得分:0)
一旦你的表中有多个行数,你就会想要更快的速度:
SELECT users.u
FROM
( SELECT idU1 AS idU from amistades where idU2 = 1
UNION
SELECT idU2 AS idU from friends where idU1 = 1
) AS x
JOIN users ON x.idU = users.u
ORDER BY users.LastLogin;