Here's an option:-- set upCREATE TABLE #tblA(PROC_CODE CHAR(5) NOT NULL, MOD_1 CHAR(2) NULL, MOD_2 CHAR(2) NULL)CREATE TABLE #tblB(PROC_CODE CHAR(5) NOT NULL, MOD_1 CHAR(2) NULL, MOD_2 CHAR(2) NULL)INSERT #tblA VALUES('S5000',NULL,NULL),('S5000','AA',NULL),('S5000','AA','AB')INSERT #tblBVALUES('S5000',NULL,NULL),('S5000','AA','AB')-- SQL Server 2005+SELECT * FROM #tblA EXCEPT SELECT * FROM #tblB -- MS Access, SQL ServerSELECT PROC_CODE,MOD_1,MOD_2 FROM (SELECT 'A' tbl,PROC_CODE,MOD_1,MOD_2 FROM #tblA UNION ALLSELECT 'B' tbl,PROC_CODE,MOD_1,MOD_2 FROM #tblB) zGROUP BY PROC_CODE,MOD_1,MOD_2HAVING MAX(tbl)='A'
You can ignore the setup part and substitute the proper table names in the other query(ies).