Home » SQL & PL/SQL » SQL & PL/SQL » select data which does not in join condition
select data which does not in join condition [message #20651] Tue, 11 June 2002 05:19 Go to next message
fairos
Messages: 2
Registered: June 2002
Junior Member
if using select ...
from tblA A, tblB B
where A.id = B.id
i got data which contain in table A & B.

how to select data in table B which does not contain
data in table A
Re: select data which does not in join condition [message #20652 is a reply to message #20651] Tue, 11 June 2002 06:23 Go to previous messageGo to next message
Suresh
Messages: 189
Registered: December 1998
Senior Member
Use Outer join

select B.*
from tblA A, tblB B
where A.id(+) = B.id
and A.id is null;
Re: select data which does not in join condition [message #20659 is a reply to message #20651] Tue, 11 June 2002 19:39 Go to previous messageGo to next message
Vikas Gupta
Messages: 115
Registered: February 2002
Senior Member
select * from tableA
minus
select * from tableB
Re: select data which does not in join condition [message #20670 is a reply to message #20651] Wed, 12 June 2002 18:10 Go to previous messageGo to next message
Su
Messages: 154
Registered: April 2002
Senior Member
No doubt, I agree with Vikas (what I just thought to give the answer, he gave it). The MINUS operator is just effecient and quicker to retrieve the data you want. But, just to be sure, as you said, if the result should be just in reverse to the equi-join you mentioned, then the way Vikas mentioned does not achieve the result you want.
If both tables are having same structure and the number of columns you are retrieving is same, then try the following out adding little modification to the Vikas's logic.

SELECT * FROM TABLEA A
MINUS
SELECT * FROM TABLEA A, TABLEB B WHERE A.COLUMN1 = B.COLUMN1;

The first SELECT returns all the rows existing in tablea (lets say 100) and the second SELECT returns only the rows those are matching with each other (lets say 65), so the final outcome of this combined query should return (100 minus 65) 35 rows of nonmatching data. Remember, when you use MINUS, the first SELECT should return more number of rows than the ones return by latter to get the right outcome. Hope you got my point. Check it out. Good luck :)
Re: select data which does not in join condition [message #20727 is a reply to message #20651] Sun, 16 June 2002 03:35 Go to previous message
kirankumar
Messages: 1
Registered: June 2002
Junior Member
select * from b
notexists ( select * from a)
Previous Topic: Create Table if not Exists.
Next Topic: how to dynamically declare a cursor based on the parameter passed to the proc!!!!!
Goto Forum:
  


Current Time: Mon May 20 14:12:37 CDT 2024