简体   繁体   中英

How to do join with multiple conditions in mysql

How can i it in single query

Get mID for uID(1) (33,34,35) select text where mID (33,34,35){based on the above result} select Name where uID(user id of mID in table b (5,6)){based on the above result}

Output

txt1  user5
txt3  user6

The only id I know is uID. How to do this in a single query.

TableA       TableB                      TableC
uID  mID    mID   Text  uID             uID    Name
1    33      33   txt1   5               1     user1
2    34      34   txt2   5               2     user2
1    35      35   txt3   6               5     user5
2    33                                  6     user6
2    34
select b.Text, c.Name
from TableA a
inner join TableB b on a.mID = b.mID
inner join TableC c on b.uID = c.uID
where a.uID = 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM