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 > Load Table where <>

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-05-12, 00:00
clemmdupree clemmdupree is offline
Registered User
 
Join Date: Sep 2011
Posts: 3
Load Table where <>

Hi there.

Trying to load new table based on the following and I am getting a nested loop join...

Customer Table
Canceled Table
New Table

I am declaring cursor as SELECT * from Customer t1, Canceled t2
where Customer.id <> Canceled.id

This is giving me a nested loop. Obviously my SQL skills are terrible. I can't figure out how to write the SQL to only load into the new table where the ID in Customer does not equal the ID Cancelled.

Any help?
Thanks all.
Reply With Quote
  #2 (permalink)  
Old 02-05-12, 00:42
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Maybe something like this:

SELECT * from Customer t1 where not exists (select 1 from Canceled t2 where t1.id = t2.id);
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-05-12, 09:32
clemmdupree clemmdupree is offline
Registered User
 
Join Date: Sep 2011
Posts: 3
Thanks

Quote:
Originally Posted by Marcus_A View Post
Maybe something like this:

SELECT * from Customer t1 where not exists (select 1 from Canceled t2 where t1.id = t2.id);
This worked. I've got to get my SQL skills up to speed. Sheesh.

Thanks, Marcus.
Reply With Quote
  #4 (permalink)  
Old 02-05-12, 10:04
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by clemmdupree View Post
This is giving me a nested loop.
What's wrong with a nested loop, and how is that related to SQL skills?

You could also use an outer join and select records that have no match.
Reply With Quote
  #5 (permalink)  
Old 02-05-12, 12:09
clemmdupree clemmdupree is offline
Registered User
 
Join Date: Sep 2011
Posts: 3
Quote:
Originally Posted by n_i View Post
What's wrong with a nested loop, and how is that related to SQL skills?

You could also use an outer join and select records that have no match.
The nested loop gave me a Cartesian product and I had to terminate the load. My SQL skills are terrible because I couldn't figure a way out of it.
Reply With Quote
Reply

Tags
loop query help

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