[英]How to apply join in 3 tables if 3rd does not have primary key?
如何在三个表之间进行联接,例如我有三个表productoption,productsize和price和t3没有主键,但是问题是productsize tbl没有主键
productoption内部联接产品尺寸内部联接价格
select * from Prices
select * from Product
select * from ProductOption
select * from ProductSize
select PriceFor, SourceID, MainPrice
from Prices
where PriceFor = 2
and SourceID in (select ProductOptionID from ProductOption where ProductId=7)
select * from Product
select ProductID, ProductName +' - '+ Convert(varchar(5),ProductID) as C
from Product
need inner join btw productoption > productsize and productoption > price
缺少主键并不会阻止您加入联接。 联接可以是您选择的任何列。 以下语法将联接3个表
SELECT A.*, B.*, C.*
FROM
A
INNER JOIN
B
INNER JOIN
C
ON B.Col1 = C.Col2
ON A.Co3 = B.Col4
但是,如果您没有覆盖联接中使用的列的索引,则性能可能会不好。 我想您的问题是如何加入3个表? 请注意,“ ON”的顺序是嵌套的,从内到外是嵌套的,表的顺序(在ON条件下)与它们在初始零件连接语句中出现的顺序相同。 可能会造成混乱
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.