怪現象
第一個SQL語句
select t.* From FileOUT t
INNER JOIN
(select Fileid,Rev from Relationfile where Relationfile.Nodeid in
(SELECT nodeid FROM
(select T1.* from DBO.tree T1 INNER JOIN
DBO.tree T2 ON T1.PARENT=T2.NODEID INNER JOIN
DBO.tree T3 ON T2.PARENT=T3.NODEID INNER JOIN
DBO.tree T4 ON T3.PARENT=T4.NODEID INNER JOIN
DBO.tree T5 ON T4.PARENT=T5.NODEID AND T5.nodename like 'C%系列% ') C
WHERE (C.NodeName like 'Part%List% ' or C.NodeName like '生產工藝規格% ' or
C.NodeName like '生產效率排拉圖% ' or C.NodeName like '馬達出廠檢驗規格% '
or C.NodeName like '馬達外形圖% ' or C.NodeName like '馬達技朮參數% ' or C.NodeName like '控制計劃% '))) as p
ON t.fileid=p.fileid and t.rev=p.rev and t.ACCEPTTEAMID= '2201A '
第二個SQL語句
delete t From FileOUT t
INNER JOIN
(select Fileid,Rev from Relationfile where Relationfile.Nodeid in
(SELECT nodeid FROM
(select T1.* from DBO.tree T1 INNER JOIN
DBO.tree T2 ON T1.PARENT=T2.NODEID INNER JOIN
DBO.tree T3 ON T2.PARENT=T3.NODEID INNER JOIN
DBO.tree T4 ON T3.PARENT=T4.NODEID INNER JOIN
DBO.tree T5 ON T4.PARENT=T5.NODEID AND T5.nodename like 'C%系列% ') C
WHERE (C.NodeName like 'Part%List% ' or C.NodeName like '生產工藝規格% ' or
C.NodeName like '生產效率排拉圖% ' or C.NodeName like '馬達出廠檢驗規格% '
or C.NodeName like '馬達外形圖% ' or C.NodeName like '馬達技朮參數% ' or C.NodeName like '控制計劃% '))) as p
ON t.fileid=p.fileid and t.rev=p.rev and t.ACCEPTTEAMID= '2201A '
以上兩句為什麼查出來的資料總數和刪除所影響的資料列數不一樣呢
[解决办法]
因为FileOUT与子查询存在一对多的关系,因此查询出的时候所列出的纪录数自然多于FileOUT原纪录数。
[解决办法]
因为FileOUT t表的一条记录以条件t.fileid=p.fileid and t.rev=p.rev and t.ACCEPTTEAMID= '2201A '与子查询连接的时候,产生了多条记录,也就是说子查询的
p.fileid,p.rev有重复
[解决办法]
查询的时候会把关联的都显示出来``而删除的时候只删除主表的``所以相对应的查出來的資料總數和刪除所影響的資料列數不一樣。
[解决办法]
建議不在用inner join 最好直接用
where,那樣子比較容易理解