Joing the Tables to get the required data, I got three tables which are connected and i want to get the data from the 3rd table

StackOverflow https://stackoverflow.com/questions/23308073

Question

My First Table Name is UserClient and it contains UserTrainerID. Using UserTrainerID, Second Table is UserTrainer and it contains UserID (I want to Know the UserID of UserTrainer using UserTrainerID), now third table is User where with the help of userID I want to get the UserName.

Was it helpful?

Solution

Select a.username from t3 a,t2 b,t1 c 
    where a.userid=b.userid and b.UserTrainerID= c.UserTrainerID ;

OTHER TIPS

Here is syntax to join three tables, I hope you will be able to join your tables accordingly:

SELECT t1.col, t3.col FROM table1 
             join table2 ON table1.primarykey = table2.foreignkey
             join table3 ON table2.primarykey = table3.foreignkey

Read more: http://javarevisited.blogspot.com/2012/11/how-to-join-three-tables-in-sql-query-mysql-sqlserver.html#ixzz2zyYzv3pD

or SQL Inner-join with 3 tables?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top