473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Left Outer Join vs. pkey in (...

We've got this whole mess trying to export data from Lotus Notes to
Great Plains. As part of the process, we need to ensure that a Notes
record is exported only once, but have the ability to re-export it if
something breaks. So, for that reason (and some others) I decided to
use a simple log table:

create ExpLog (
ExpDateTime Datetime not null,
DBID varchar(16) not null,
docUNID varchar(32) not null,
)

So, the code records the records datetime, and the DBID and docUNID
(which uniquely identifies every Lotus Notes "record"). My question is
in the sql that exports the records. Which is likely to be more
efficient?

select
field1,
...
from LotusNotes LN left outer join ExpLog EL on LN.DBID = EL.DBID and
LN.docUNID = EL.docUNID
where EL.docUNID is null

or

select
field1,
...
from LotusNotes LN
where
ln.DBID not in (select DBID from EL)
and
ln.docUNID not in (select docUNID from EL)

How would one go about figuring this out assuming that the SQL is going
into a DTS package. (I think that means the plan isn't saved?)
Thanks.

Jul 23 '05 #1
1 1548
EoRaptor013 (rc*******@patmedia.net) writes:
So, the code records the records datetime, and the DBID and docUNID
(which uniquely identifies every Lotus Notes "record"). My question is
in the sql that exports the records. Which is likely to be more
efficient?

select
field1,
...
from LotusNotes LN left outer join ExpLog EL on LN.DBID = EL.DBID and
LN.docUNID = EL.docUNID
where EL.docUNID is null

or

select
field1,
...
from LotusNotes LN
where
ln.DBID not in (select DBID from EL)
and
ln.docUNID not in (select docUNID from EL)
For one thing, they don't seem to mean the same thing to me. Maybe
they do, but it's difficult to understand. There is also a gotcha when
NULL values are involved.

I would write this as:

SELECT field1, ...
FROM LotusNotes LN
WHERE NOT EXISTS (SELECT *
FROM EL
WHERE LN.DBID = EL.DBID
AND LN.docUNID = EL.docUNID)

Not because this is guaranteed to be the most effective, but because
it expresses what you are trying to achieve. Some people claim that
the LEFT JOIN method is more effective. On the other hand, the
optimizer may rewrite one into the other, so it may not make any
differnce at all.
How would one go about figuring this out assuming that the SQL is going
into a DTS package. (I think that means the plan isn't saved?)


I can't see that it would matter whether this is in DTS or elsewhere.
Then again, I don't know DTS, so I may have missed something.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: shumaker | last post by:
The query: SELECT BTbl.PKey, BTbl.Result FROM BTbl INNER JOIN ATbl ON BTbl.PKey = ATbl.PKey WHERE (ATbl.Status = 'DROPPED') AND (BTbl.Result <> 'RESOLVED') Returns no rows. If...
3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
1
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
5
by: Todd | last post by:
Data related to the query I'm working on is structured such that TableA and TableB are 1-many(optional). If an item on TableA has children on TableB, I need to use the Max(tstamp) from Table B in...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
1
by: nico3334 | last post by:
I have a query that currently pulls data from a main table and a second table using LEFT OUTER JOIN. I know how to do make another LEFT OUTER JOIN with the main table, but I want to add another LEFT...
1
by: teneesh | last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.