有这样一个SQL,求教:
A表:ID,FILE_PATH,FILE_VERSION_ID
B表:ID,FILE_PATH
需要更新:
A表的FILE_VERSION_ID = B表的ID,
条件:A表的FILE_PATH = B表的FILE_PATH
就是SET XX = (多个结果集)
WHERE FILE_PATH = (多个结果集)
需要怎么对应起来呢。
select t2.file_version_id from file_version t2 inner join file_file t3
on t3.file_path=t2.file_final_path
这是查询出的file_version_id
select t4.file_final_path from file_version
这是查询出的file_path
update file_file t1 set t1.file_version_id =
(查询出的file_version_id)
where t5.file_path = (查询出的file_path)
有可能查询出的file_version_id的数量比查询出的file_final_path的数量多。
因为file_file表中的file_path可以重复,而file_version表中只存最新的版本。
------解决方案--------------------
--查询
select ID,FILE_PATH,FILE_VERSION_ID from A where exists(select id from b where b.file_paht=A.FILE_PATH);
--更新
update A set a.FILE_VERSION_ID=(select id from b where b.file_paht=A.FILE_PATH where rownum=1)
------解决方案--------------------