Sql 连接3个表,以便对于其唯一记录,可以从第三个表检索数据

Sql 连接3个表,以便对于其唯一记录,可以从第三个表检索数据,sql,database,Sql,Database,我有三张桌子- 表1(t1)包含多个accountno实例表2(t2)包含accountno及其customerno的唯一实例(t2与t1相比有更多的帐户)表3(t3)包含customerno的详细信息 我希望连接这三个表,以便对于来自t1的accountnos的唯一实例,我可以从t3检索客户详细信息。如果t3中不存在客户详细信息,我仍然需要t1中的accountno 例如: t1.accountno x x m t2.accountno t2.customerno x c

我有三张桌子-
表1(t1)包含多个accountno实例表2(t2)包含accountno及其customerno的唯一实例(t2与t1相比有更多的帐户)表3(t3)包含customerno的详细信息

我希望连接这三个表,以便对于来自t1的accountnos的唯一实例,我可以从t3检索客户详细信息。如果t3中不存在客户详细信息,我仍然需要t1中的accountno

例如:

t1.accountno  
x  
x  
m  

t2.accountno t2.customerno  
x custid1  
y custid2  
z custid3  

t3.customerno t3.customername  
custid1 John  
custid2 Roy  

expected o/p  
t1.accountno t2.customerno t3.customername  
x custid1 John  

它是简单的内部联接和分组方式,以避免重复值

SELECT t1.accountno, t2.customerno, t3.customername FROM t1
    JOIN t2 cn ON t1.accountno = t2.accountno 
    JOIN t3 cn ON t2.customerno = t3.customerno 
Group By t1.accountno, t2.customerno, t3.customername

添加一些示例表数据和预期结果-作为格式化文本,而不是图像。同时向我们展示您当前的查询尝试。我已经给出了示例数据,但不确定如何格式化数据。看起来,常规内部连接是一种方法。