mariadb - Excluding data from a queried table after sql join -


i don't know if not thinking correct join structure can't seem results want join.

this sql schema these 3 tables

schema

select target, sender, message, amount, transactiontime, transaction_id  transactions  join accounts on transactions.sender=accounts.account_id  join users on users.user_id=accounts.user_id  users.user_id=40  union  select target, sender, message, amount, transactiontime, transaction_id  transactions  join accounts on transactions.target=accounts.account_id  join users on users.user_id=accounts.user_id users.user_id=40  order transactiontime  limit 20; 

sql result table

this query have , queries through 3 tables. want information transaction table want exclude account_id not associated user. in case user id 40 , account_id 57. wondering how able rid of that. how 3 not show up. bonus, structure of query including id's associated accounts. if account_id 4 , 57 belonged 1 user , money flowing between them. how able see both 4 , 57 in transaction query table?

to "exclude account_id not associated user", not mean "include accounts associated user"?

declare @user_id int = 40  select target, sender, message, amount, transactiontime, transaction_id  transactions  join accounts   on  transactions.sender=accounts.account_id                  or  transactions.target=accounts.account_id  accounts.user_id=@user_id  

if goal see transaction of accounts both (sender , target) belong same user:

declare @user_id int = 40  select target, sender, message, amount, transactiontime, transaction_id  transactions  join accounts  send on  transactions.sender=send.account_id  join accounts  targ on  transactions.target=targ.account_id  send.user_id=@user_id  ,   targ.user_id=@user_id  

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -