我的源控制数据库有两个表 - PRJ
和PRJHIST
,两者都有相同的列和约束。
例如。 PRJ
和PRJHIST
包含以下行
PRJ TABLE
PRJ_NAME PRJ_TYPE PRJ_VERSION PRJ_AUTHOR PRJ_LANG
PRJ001 SCRIPT 3 MARK PERL
PRJ002 SCRIPT 2 JACK KSH
PRJ003 BINARY 4 JADE C++
PRJHIST TABLE
PRJ_NAME PRJ_TYPE PRJ_VERSION PRJ_AUTHOR PRJ_LANG
PRJ001 SCRIPT 1 MARK PERL
PRJ001 SCRIPT 2 MARK PERL
PRJ001 SCRIPT 3 MARK PERL
PRJ002 SCRIPT 1 JACK KSH
PRJ002 SCRIPT 2 JACK KSH
PRJ003 BINARY 1 JADE C++
PRJ003 BINARY 2 JADE C++
PRJ003 BINARY 3 JADE C++
PRJ003 BINARY 4 JADE C++
PRJ
表始终包含PRJHIST
表
如何删除max(PRJ_VERSION)
表中PRJHIST
的所有行?
即我需要从PRJHIST
表
PRJ001 SCRIPT 3 MARK PERL
PRJ002 SCRIPT 2 JACK KSH
PRJ003 BINARY 4 JADE C++
答案 0 :(得分:1)
DELETE FROM PRJHIST a
WHERE EXISTS (SELECT 'X'
FROM PRJ b
WHERE a.PRJ_NAME = b.PRJ_NAME
AND a.PRJ_VERSION = b.PRJ_VERSION);