Its not really a subtraction I\'m looking for. And I know its not a union or intersection... I have been given a long and complex stored procedure that returns a table of
SELECT both.*
FROM both LEFT OTUER JOIN inactives USING (whatever_id)
WHERE inactives.whatever_id IS NULL;
or
SELECT * FROM both
EXCEPT
SELECT * FROM inactives;
SELECT * FROM Table1
LEFT JOIN Table2 on Table1.id = Table2.id
WHERE Table2.id IS NULL
this should work on almost any database engine
In MS TSql, I think you want the EXCEPT keyword.
query1 EXCEPT query2
Which will return all rows found in the first query that are not also found in the second query.
You can just used the first sp that return the Active & Inactive and in WHERE cluse put condition for the document status =inactive, you wil get inactive document only.
Assuming there are unique IDs that correspond across the two tables:
select * from table_both b
where not exists (select * from table_active a where a.id = b.id)
I believe EXCEPT is what you are looking for. Syntax is similar to UNION or INTERSECT.