0
考虑这三个表:使用联接涉及视图和表返回更多的记录比预期
内容:
Id(pk), Name, and ContentTypeId(fk from ContentType)
ContentTypeId:
此表将有值如
1文本
2个
...
Id(pk), Value
ContentUpdates:
Id(fk from Content), Status, UpdateDate
所有三个为报表获取数据有一种观点像这样:
select C.Id, C.Name, CT.Value, CU.UpdateDate
from ContentUpdates CU
join Content C
On CU.Id = C.Id
join ContentType CT
On C.ContentTypeId = CT.Id;
目前这个特定的视图给了我800条记录。
我在哪里,我需要所有这些列类似的要求加上一个过滤器基于在ContentUpdates表中的状态列
我想用这个视图上的ID加入“ContentUpdates”表。
例如,我可能想要获取状态为5的所有内容。 当前只有2条记录具有该状态,但是在视图上使用JOIN时,结果集的记录方式比这更多。
我在做什么错?
可以查看实际使用还是我更好用这样的:
SELECT C.Id, C.Name, CT.Value, CU.UpdateDate
FROM ContentUpdates CU
JOIN Content C
On CS.Id = C.Id
JOIN ContentType CT
On C.ContentTypeId = CT.Id
WHERE CU.Status = 5;