If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > EXCEPT and WHERE clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-04, 16:30
chium chium is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
EXCEPT and WHERE clause

Hi,

I have a query:

select assettag from amPortfolio EXCEPT(select assettag from amComputer)

provided that these two table has a commom field assettag and they do not
have identical fields.

I would like to transform the same query using a WHERE clause.

Would anybody have idea how to do it? Can use anything like INTERSECTS, UNION...

Thanks,

Mike
Reply With Quote
  #2 (permalink)  
Old 08-18-04, 17:10
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
The simplest way is
select assettag from amPortfolio where assettag not in (select assettag from amComputer)
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 08-18-04, 17:30
chium chium is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
I tried that.

Strange that it returns 0 records...

I used:

select assettag from amPortfolio where assettag in (select assettag from amComputer)

It gives me 5482 records..

I then did

select count(distinct assettag) from amComputer

It gives me 5510

Then

select count(distinct assettag) from amPortfolio

It gives me 8010

I know obviously some assettag in amPortfolio is not in amComputer... but somehow I got 0 records when doing the query..
Reply With Quote
  #4 (permalink)  
Old 08-19-04, 01:59
fadace fadace is offline
Registered User
 
Join Date: Nov 2002
Location: Switzerland
Posts: 523
If you add a condition in the field of the outer table of a except join, you will receive 0 row because execpt returns the fields that have no concordance.

for this type of query, prefer the "where not exists (select... from ... where...)"
__________________
F. Celaia
DBA Sybase/DB2/Oracle/MS-SQL
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On