我不知道我是否没有考虑正确的连接结构,但似乎无法从此连接中获得我想要的结果。在sql连接之后排除查询表中的数据
这是我这3个表
select target, sender, message, amount, transactiontime, transaction_id
from transactions
join accounts on transactions.sender=accounts.account_id
join users on users.user_id=accounts.user_id
where users.user_id=40
union
select target, sender, message, amount, transactiontime, transaction_id
from transactions
join accounts on transactions.target=accounts.account_id
join users on users.user_id=accounts.user_id
where users.user_id=40
order by transactiontime
limit 20;
这是我有查询,并将其通过3个表查询的SQL模式。基本上我只需要来自我的交易表的信息,但我想排除任何不与该用户关联的account_id。在这种情况下,用户ID是40,他们的account_id是57.想知道如何才能摆脱这种情况。基本上如何让3不出现。另外作为奖励,将查询的结构包括id与我的账户相关联。就像account_id 4和57属于一个用户,并且钱在他们之间流动一样。我如何能够在我的交易查询表中看到4和57?
我不明白这一点。您显示的是用户40的前20个交易,无论通过他们的哪个账户,无论是作为发件人还是收件人。这不是你想要的吗?你还想要什么?如果您向我们展示您获得的结果与您期望的结果(以及文本请不要作为图片链接),这可能会有所帮助。 –