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
All good answers, but missing one point: The questioner (OP) has stored procedures...
You have to define temporary tables (based on your platform) to load the data
INSERT ...
EXEC getActive
INSERT ...
EXEC getInactive
Then use EXCEPT/EXISTS/MINUS/IN/OUTER JOIN/etc...
SELECT roll_number FROM profile WHERE(catagory='Attest and Eat' or catagory='Live and Eat') and status='OK' EXCEPT SELECT roll_number from meal_status WHERE date='29' AND month='1'
You can try this kind of command to subtract a table from another one.
What's your DB engine?
In Oracle, you could use MINUS set operation.
In MS SQLServer 2005 and newer you can use EXCEPT.
For doing the subtraction between three tables I have used the following query:
Basically I have three tables.. table 1, table 2, table 3. Firstly I have done the subtraction of table 1 and table 2 and then done the subtraction between the the result of previous query and table 3.
select v3.Material, ((v1.Qty-v2.Qty)-v3.Qty) as Quantity
from table1 v1, table2 v2, table3 v3
where (v1.Material=v2.Material
and v1.Material=v3.Material
and v2.Material=v3.Material)
The set operation you are looking for is called MINUS, but in SQL Server the keyword is EXCEPT
SELECT ... // all documents
EXCEPT
SELECT ... // active documents
I believe that the EXCEPT set operation became available in SQL Server 2005.
select * from MyTable1
where MyTable1.Field1 not in (
select Field1 from MyTable2)