一个表有两个外键都指向另一个表的主键时,如何检索他们的数据?

例如,表TableA有两个列,puserID和friendID。

        表TableB有两个列,userID和userName。

        我们怎样检索数据并让这些数据按照puserID、puserIDName、friendID和friend_userName显示呢?

记录:

SELECT t1.puserID,t2.userNameAS puserIDName ,t1.friendID,t3.userName AS friend_userName
      FROM TableA AS t1
    INNER 
      JOIN TableB AS t2 
        ON t2.userID= t1.puserID 
    INNER 
      JOIN TableB AS t3 
        ON t3.userID= t1.friendID

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2021-12-08
  • 2021-08-27
  • 2021-12-17
猜你喜欢
  • 2021-08-21
  • 2021-12-07
  • 2021-09-24
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案