Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2007-10-16
8
Medium Priority
?
2,236 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Iman_Davoodian
8 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 20085719
SELECT * from TableA a WHERE NOT EXISTS (SELECT 1 FROM tableB where a.a1 = b.b1 and a.a2 = b.b2 )
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20085925
SELECT * from TableA a WHERE NOT(A.A1) in (SELECT B.B1 FROM TableB b)
0
 
LVL 8

Expert Comment

by:matrix_aash
ID: 20086230
SELECT A1,A2 FROM TABLE1 EXCEPT SELECT B1,B2 FROM TABLE2

Hope this helps

Aash.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20087842
select a.*
from tableA a
left join tableB b
  on a.a1 = b.b1
 and a.a2 = b.b2
where b.b1 is null

0
 

Author Comment

by:Iman_Davoodian
ID: 20089603
Dear matrix_aashh , the except operator doesn't work in SQL SERVER 2000
0
 

Author Comment

by:Iman_Davoodian
ID: 20089628
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
0
 

Author Comment

by:Iman_Davoodian
ID: 20089686
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 ?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20090821
>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...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

576 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question