tags:

views:

21

answers:

1

i have 3 tables structure is below

tbl_login

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?

+1  A: 

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
Lieven
Thankyou very much!
diEcho
can we use `JOIN` instead of `INNER JOIN`? is there any difference?
diEcho
`INNER` is implicitly used when no other join predicate is present. Personally, I always write the predicate for clarity.
Lieven