Link to home
Start Free TrialLog in
Avatar of Iman_Davoodian
Iman_Davoodian

asked on

Creating a Query to do what minus operator do in SQL SERVER 2000

Suppose we have to Table A(a1,a2) , B(b1,b2)
I need a query that results all the records which exists in Table A and not exists in Table B , THe operation like what Minu Operator does . But as you know , it's not possible to use minu operator in SQL SERVER 2000
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT * from TableA a WHERE NOT(A.A1) in (SELECT B.B1 FROM TableB b)
SELECT A1,A2 FROM TABLE1 EXCEPT SELECT B1,B2 FROM TABLE2

Hope this helps

Aash.
select a.*
from tableA a
left join tableB b
  on a.a1 = b.b1
 and a.a2 = b.b2
where b.b1 is null

Avatar of Iman_Davoodian
Iman_Davoodian

ASKER

Dear matrix_aashh , the except operator doesn't work in SQL SERVER 2000
Dear SQL_SERVER_DBA , the code which you've offered results incorrectly while you we have the same values in the first fields and different values in second fields
Dear angelll , thanks for you answer , it seems you answer is correct , but I couldn't undrestand the reason of "where b.b1 is null" . I guess it shouldn't work somewhere , am I right ?
>Dear angelll , thanks for you answer , it seems you answer is correct , but I couldn't undrestand the reason of "where b.b1 is null" . I guess it shouldn't work somewhere , am I right ?

it should work.
just try to run the query without that part, and add b.b1 in the select list, and see the values of b.b1 in regards t the rows you want to have returned...