如何通过SQL JOIN从三个不同的表中追踪出值?

问题描述 投票:0回答:2

我有如下 3 张桌子

table_1

securityno name    price
1           a11    12.12
2           z11    44.4

table_2

name      identifier Mainprice
a11_bond  NO34         11
z22_bond  NO98         22

table_3
securityno name    identifier 
1           a11    NO34         
2           z11    NO98         

我想检查

table_1
的价格是否正确。我只想显示来自
table_2
的输出
table_1
数据和
Mainprice
列。
table_2

我正在尝试

select * from table_1 left join table_2 on table_3

使用3张桌子失败。

sql sql-server t-sql join
2个回答
2
投票

securityno name price Mainprice 1 a11 12.12 11 2 z11 44.4 22



2
投票
SELECT t1.*, t2.Mainprice FROM table_1 AS t1 LEFT JOIN table_3 AS t3 ON t1.securityno = t3.securityno AND t1.name = t3.name INNER JOIN table_2 AS t2 ON t2.identifier = t3.identifier


INNER JOIN

演示

© www.soinside.com 2019 - 2024. All rights reserved.