--有两张表[3d_Zf_Tzje]数据表、[3d_Zf_Tzje_Record]数据记录表
--[3d_Zf_Tzje_Record]的TzjeId关联[3d_Zf_Tzje]的Id
select top 1 Id,Cid,Je,AddTime,AddId,AddContent from [3d_Zf_Tzje] where Id in (select TzjeId from [3d_Zf_Tzje_Record] where State=0) and Cid=125
--有两张表[3d_Zf_Tzje]数据表、[3d_Zf_Tzje_Record]数据记录表
--[3d_Zf_Tzje_Record]的TzjeId关联[3d_Zf_Tzje]的Id
select top 1 Id,Cid,Je,AddTime,AddId,AddContent from [3d_Zf_Tzje] where Id in (select TzjeId from [3d_Zf_Tzje_Record] where State=0) and Cid=125
很久没写了,给你点意见,先将两张表联系起来,这样查询效率高,from [3d_Zf_Tzje],[3d_Zf_Tzje_Record],你可以通过id联系起来,然后 再where state =0 and cid =125。
这个语句本来就不复杂,从写法上有三种:
in
exists
join
具体哪种写法效率高,需要实际看一下执行计划和执行时间。
如果3d_Zf_Tzje_Record表数据量比较大,建议写成join的语法,减少3d_Zf_Tzje_Record表的查询次数。
1 回答2.4k 阅读✓ 已解决
1 回答2.4k 阅读✓ 已解决
1 回答944 阅读✓ 已解决