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

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.

有帮助吗?

解决方案

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

其他提示

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top