Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old April 30th, 2003, 02:06 AM
shafan's Avatar
shafan shafan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 123 shafan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 51 sec
Reputation Power: 6
getting mutually exclusive data from 2 tables :SOLVED

Hi,
I'm trying to extract all the records which DO NOT exist in another table based on a joined field.
Is there another way of doing it besides
"...WHERE JoinedFieldValue NOT IN( comma seperated value list)" ?

thanx

Last edited by shafan : May 4th, 2003 at 02:12 AM.

Reply With Quote
  #2  
Old April 30th, 2003, 02:30 AM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 11
Use a left join like
SELECT t1.* FROM table1 t1 LEFT JOIN table2 t2 ON t1.id = t2.id WHERE t2.id IS NULL

//NoXcuz
__________________
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep

Reply With Quote
  #3  
Old April 30th, 2003, 04:19 AM
shafan's Avatar
shafan shafan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 123 shafan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 51 sec
Reputation Power: 6
no good.
for example:
I have in table 1 IDs 1, 2, 5
and in table 2 IDs 1, 2, 3, 4, 5

I want a query that will return IDs 3 and 4 (the ones which are not present in both tables).

There are no Null values in the compared field.

thanx

Reply With Quote
  #4  
Old April 30th, 2003, 05:12 AM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 11
I don't know what you tried, but with your given example in Postgresql:
Code:
test=# create table table1 (
test(# id int);
CREATE
test=# insert into table1 values (1);
INSERT 22516 1
test=# insert into table1 values (2);
INSERT 22517 1
test=# insert into table1 values (5);
INSERT 22518 1
test=# create table table2 (
test(# id int);
CREATE
test=# insert into table2 values (1);
INSERT 22521 1
test=# insert into table2 values (2);
INSERT 22522 1
test=# insert into table2 values (3);
INSERT 22523 1
test=# insert into table2 values (4);
INSERT 22524 1
test=# insert into table2 values (5);
INSERT 22525 1
test=# SELECT t2.id FROM table2 t2 LEFT JOIN table1 t1 ON t2.id = t1.id WHERE t1.id IS NULL;
 id
----
  3
  4
(2 rows)


Using a LEFT JOIN (or RIGHT JOIN) will produce NULL values in the above context, wheter the table itself contains them or not.

//NoXcuz

Reply With Quote
  #5  
Old April 30th, 2003, 05:57 AM
shafan's Avatar
shafan shafan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 123 shafan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 51 sec
Reputation Power: 6
I didn't provide all the information.
The tables sit in diferent data bases: one is Access2000 and the other is FoxPro 6.

I have 2 ADO connections - can't use a JOIN.

Sorry...

Reply With Quote
  #6  
Old April 30th, 2003, 06:08 AM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 11
Two alternatives as I see it.
  • Use a scripting language and arrays
    If the result sets aren't too big, you can select all id' from table1 and store them in an array. Then do the same hing for table2 and compare the arrays. The difference is your answer...
  • Temporary (or permanent) tables in either database
    Don't know if Acess or Foxpro supports temporary tables, but if they don't you could create a table to store the result and drop it afterwards. Say that you use Access for example. Do a 'select all id's from foxpro-table' and create a table in Access where you store the result set. Then you can run the query in my previous post to get the difference.

//NoXcuz

Reply With Quote
  #7  
Old May 4th, 2003, 02:11 AM
shafan's Avatar
shafan shafan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 123 shafan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 51 sec
Reputation Power: 6
I've filled 2 arrays and then compared them.

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > getting mutually exclusive data from 2 tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway