Solved

NOT IN alternative in 2008

Posted on 2013-01-31
4
124 Views
Last Modified: 2013-01-31
is there any new efficient syntax to rewrite
SELECT  * from table1 where WHERE NNS NOT IN  (SELECT NNS FROM table2)
in 2008?
0
Comment
Question by:25112
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:Jared_S
Jared_S earned 250 total points
ID: 38840370
select * from table1 where not exists
(select null from table2 where table2.nns = table1.nns)

will work in any release and is much much more efficient than NOT IN.
0
 
LVL 39

Accepted Solution

by:
lcohan earned 250 total points
ID: 38840730
You can also look at new(er) EXCEPT (and INTERSECT) commands so a sample code would be like:

select * from table1
except
select * from table2 where table2.nns = table1.nns

if you have TEXT fileds you need to CAST(col_name AS VARCHAR(MAX)) for the EXCEPT to work.
0
 
LVL 5

Author Comment

by:25112
ID: 38840845
thanks
0
 
LVL 12

Expert Comment

by:Jared_S
ID: 38840891
Also, be aware that except and intersect will compare EACH field in the row, not just the ID.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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