|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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. |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
||||
|
||||
|
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... |
|
#6
|
||||
|
||||
|
Two alternatives as I see it.
//NoXcuz |
|
#7
|
||||
|
||||
|
I've filled 2 arrays and then compared them.
Thanks! |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > getting mutually exclusive data from 2 tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|