473,385 Members | 2,004 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,385 software developers and data experts.

NOT problem. this should be easy

Should be easy, but I've been trying to figure this out for about half
an hour with no luck. There is a table 'Cybex' which has all the Cybex
products we sell, and a table 'Datasheets' which contains a list of
the datasheets available for products. Both tables have a PartNumber
column.

On with the problem. If i do SELECT * FROM Cybex, it lists the 1000 or
so products. and then SELECT * FROM DataSheets, it lists the 800
datasheets we have for the cybex products. this should mean that there
are around 200 products without the datasheets

So, to get those 200 products without datasheets, shouldnt this work?
SELECT * FROM Cybex WHERE NOT(Cybex.PartNumber IN (SELECT
DataSheets.Partnumber FROM DataSheets))

It is returning 0 results. Any help would be appreciated, thanks.
Jul 20 '05 #1
3 2181
Andy,

DDL would help here. I'm assuming that PartNumber is a key for Cybex and
NOT NULL. But is Partnumber NULL for any datasheets? If any datasheet is
without a part number, you will get no rows in your result as NOT UNKNOWN =
UNKNOWN.

Try

SELECT *
FROM Cybex
WHERE PartNumber NOT IN (
SELECT PartNumber
FROM DataSheets
WHERE PartNumber IS NOT NULL);

or

SELECT *
FROM Cybex
WHERE NOT EXISTS (
SELECT *
FROM DataSheets
WHERE PartNumber = Cybex.PartNumber);

If my assumptions are wrong, try posting the DDL for your tables and we can
have another go.

Hope that helps,
Rich
"Andy Visniewski" <an**@pepperell.net> wrote in message
news:f6**************************@posting.google.c om...
Should be easy, but I've been trying to figure this out for about half
an hour with no luck. There is a table 'Cybex' which has all the Cybex
products we sell, and a table 'Datasheets' which contains a list of
the datasheets available for products. Both tables have a PartNumber
column.

On with the problem. If i do SELECT * FROM Cybex, it lists the 1000 or
so products. and then SELECT * FROM DataSheets, it lists the 800
datasheets we have for the cybex products. this should mean that there
are around 200 products without the datasheets

So, to get those 200 products without datasheets, shouldnt this work?
SELECT * FROM Cybex WHERE NOT(Cybex.PartNumber IN (SELECT
DataSheets.Partnumber FROM DataSheets))

It is returning 0 results. Any help would be appreciated, thanks.

Jul 20 '05 #2
an**@pepperell.net (Andy Visniewski) wrote in message news:<f6**************************@posting.google. com>...
Should be easy, but I've been trying to figure this out for about half
an hour with no luck. There is a table 'Cybex' which has all the Cybex
products we sell, and a table 'Datasheets' which contains a list of
the datasheets available for products. Both tables have a PartNumber
column.

On with the problem. If i do SELECT * FROM Cybex, it lists the 1000 or
so products. and then SELECT * FROM DataSheets, it lists the 800
datasheets we have for the cybex products. this should mean that there
are around 200 products without the datasheets

So, to get those 200 products without datasheets, shouldnt this work?
SELECT * FROM Cybex WHERE NOT(Cybex.PartNumber IN (SELECT
DataSheets.Partnumber FROM DataSheets))

It is returning 0 results. Any help would be appreciated, thanks.


Andy

A more elegent and better performing solution would be to do a left
join and select records where datasheet table returns null, i.e.

select * from cybex a left join datasheets b on a.partnumber =
b.partnumber
where b.partnumber is null

hth
Hodge
Jul 20 '05 #3
Tony,

Elegance is a subjective matter, but there's no reason that one of these
formulations should outperform the others in theory. As they describe the
same result, an intelligent DBMS should resolve them all to the same
(hopefully optimal) query plan. Consider this example using the pubs
database.

SELECT *
FROM publishers
WHERE pub_id NOT IN (
SELECT pub_id
FROM titles
WHERE pub_id IS NOT NULL);

SELECT *
FROM publishers AS p
WHERE NOT EXISTS (
SELECT *
FROM titles
WHERE pub_id=p.pub_id);

SELECT p.*
FROM
publishers AS p LEFT JOIN
titles AS t ON p.pub_id=t.pub_id
WHERE
t.pub_id IS NULL;
On my laptop, Query Analyzer shows me three nearly identical query plans.
As it happens, the third is the worst and the second is the best. (For the
sake of completeness, other formulations using ALL, ANY, and SOME are
handled exactly as NOT IN.) There's no reason that NOT EXISTS should always
produce the best plan or that the LEFT JOIN query should always produce the
worst (given that the plans are different in the first place). These things
are influenced by many factors. So far as I can see, the third technique
has only one constant advantage over the others: that it can be used easily
by non-programmers with drag-and-drop interfaces such as Access.

Rich
"Tony Hodgson" <to**@exactconsulting.co.uk> wrote in message
news:a7*************************@posting.google.co m...
an**@pepperell.net (Andy Visniewski) wrote in message

news:<f6**************************@posting.google. com>...
Should be easy, but I've been trying to figure this out for about half
an hour with no luck. There is a table 'Cybex' which has all the Cybex
products we sell, and a table 'Datasheets' which contains a list of
the datasheets available for products. Both tables have a PartNumber
column.

On with the problem. If i do SELECT * FROM Cybex, it lists the 1000 or
so products. and then SELECT * FROM DataSheets, it lists the 800
datasheets we have for the cybex products. this should mean that there
are around 200 products without the datasheets

So, to get those 200 products without datasheets, shouldnt this work?
SELECT * FROM Cybex WHERE NOT(Cybex.PartNumber IN (SELECT
DataSheets.Partnumber FROM DataSheets))

It is returning 0 results. Any help would be appreciated, thanks.


Andy

A more elegent and better performing solution would be to do a left
join and select records where datasheet table returns null, i.e.

select * from cybex a left join datasheets b on a.partnumber =
b.partnumber
where b.partnumber is null

hth
Hodge

Jul 20 '05 #4

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

Similar topics

2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
3
by: geoffblanduk_nospam | last post by:
Given a set of intervals {i1, i2, i3, ...} a list is produced; the base items (0) are placed one at a time into the stream and after the ix one a interval item (1, 2, 3, etc) of the correct type is...
4
by: snowweb | last post by:
I am trying to implement a CSS hierarchical unfolding menu on a site. The thing is, it needs to be dynamically populated from the results of a database query. I previously had the menu working but...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
34
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
60
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
On May 3, 8:09 am, apati...@gmail.com wrote: A programmer that uses Vista? :O Vista is a hog of an operating system. Downgrade to Windows XP or get yourself a Linux distro.
0
by: gdrude | last post by:
I should start of by letting everyone know that I am not an experienced programmer. I have read a number of books on OOP languages and settled on Python to solve this particular problem. ...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.