开发者

can we use join inside join in mysql?

开发者 https://www.devze.com 2023-01-01 02:22 出处:网络
i have 3 tables structure is below tbl_log开发者_StackOverflowin login_id | login_name 1|keshav tbl_role

i have 3 tables structure is below

tbl_log开发者_StackOverflowin

login_id | login_name 
   1     |  keshav

tbl_role

role_id | login_id( refer to tbl_login.login_id)
 1      |    1

tbl_stuff

stuff_id | role_id( refer to tbl_role.role_id)
   1     |   1

i need data in follow format

stuff_id | login_name
   1     |   keshav

how to use JOIN to retrive the above data in mysql?


You can keep joining tables with eachother on (almost) whatever parameters you like. As far as the database engine is concerned, it doesn't care about the name or meaning of the parameters you are joining (you could be joining a name with a height for instance).

It might be helpfull to read up on joins here.

SELECT  st.stuff_id
        , l.login_name
FROM    dbo.tbl_stuff st
        INNER JOIN dbo.tbl_role r ON r.role_id = st.role_id
        INNER JOIN dbo.tbl_login l ON l.login_id = r.login_id
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号