【问题标题】: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加入表以获取所需的数据,我得到了三个连接的表,我想从第三个表中获取数据
【发布时间】:2014-04-26 07:33:42
【问题描述】:

我的第一个表名称是 UserClient,它包含 UserTrainerID。使用UserTrainerID,第二个表是UserTrainer,它包含UserID(我想知道UserTrainerUserID使用UserTrainerID),现在第三个表是User,在@987654330的帮助下@我想得到UserName

【问题讨论】:

    标签: sql database sql-server-2008 left-join inner-join


    【解决方案1】:
    Select a.username from t3 a,t2 b,t1 c 
        where a.userid=b.userid and b.UserTrainerID= c.UserTrainerID ;
    

    【讨论】:

    • 现在最好将连接条件放在ON 子句而不是WHERE 子句中。
    【解决方案2】:

    这里是连接三个表的语法,我希望你能相应地加入你的表:

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

    阅读更多:http://javarevisited.blogspot.com/2012/11/how-to-join-three-tables-in-sql-query-mysql-sqlserver.html#ixzz2zyYzv3pD

    SQL Inner-join with 3 tables?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2020-09-01
      • 2019-08-09
      • 2014-01-23
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      相关资源
      最近更新 更多