Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I 'subtract' sql tables?

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 active and inactive documents. I have also been given a similar stored procedure that returns another table that contains only the active documents.

How could I get a table of inactive documents using these two store procedures?

We are using SQL Server 2005.

like image 262
swolff1978 Avatar asked Sep 03 '09 14:09

swolff1978


People also ask

How do you write subtraction in SQL?

The SQL minus (-) operator is used to subtract one expression or number from another expression or number.

How do you sum and MINUS in SQL?

Multiply the subtract from data by (-1) and then sum() the both amount then you will get subtracted amount. Highly active question.


1 Answers

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.

like image 68
LBushkin Avatar answered Oct 07 '22 19:10

LBushkin