Home » SQL & PL/SQL » SQL & PL/SQL » comparing the result of multiple SELECT statements (Oracle 11g, Win7)
comparing the result of multiple SELECT statements [message #610769] Mon, 24 March 2014 03:53 Go to next message
nischalinn
Messages: 118
Registered: May 2012
Location: nepal
Senior Member

how to compare the results of two SELECT query, if all of them gives the same result the output
should be NULL.
CREATE TABLE TEST1
(
	check_point varchar2(10)
);

insert into TEST1 values ('100mm');
insert into TEST1 values ('500mm');
insert into TEST1 values ('250mm');

CREATE TABLE TEST11
(
	base_check_point varchar2(10)
);

insert into TEST11 values ('100mm');
insert into TEST11 values ('500mm');
insert into TEST11 values ('250mm');



how to check if these two statements:
select distinct check_point from test1
and
select distinct base_check_point from test11
give the same result or not?

One way is to use MINUS query, but I've to use MINUS two times for comparing the result from both the tables.

How can I do this?
Re: comparing the result of multiple SELECT statements [message #610775 is a reply to message #610769] Mon, 24 March 2014 04:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You can use full outer join, see Join.

Re: comparing the result of multiple SELECT statements [message #610788 is a reply to message #610775] Mon, 24 March 2014 05:54 Go to previous messageGo to next message
msol25
Messages: 396
Registered: June 2011
Senior Member
hi,

Please execute query in sequence.If getting same result that means both tables having matching records for column check_point.:


select  count(distinct check_point)
from    test1;

o/p -> 3

select  count(distinct base_check_point)
from    test11;

o/p -> 3


select  count(1)
from(
        select   * from test11
        INTERSECT
        select  * from test1
     )

o/p -> 3


Re: comparing the result of multiple SELECT statements [message #610793 is a reply to message #610788] Mon, 24 March 2014 06:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

As OP don't want to do 2 MINUS (in a query) I doubt he wants to execute 3 queries with one with an INTERSEC.
In addition, OP wants the differences between the 2 not some counts which return nothing about the differences themselves.

Re: comparing the result of multiple SELECT statements [message #610796 is a reply to message #610793] Mon, 24 March 2014 07:02 Go to previous messageGo to next message
nischalinn
Messages: 118
Registered: May 2012
Location: nepal
Senior Member
You are right Michel Cadot.
Re: comparing the result of multiple SELECT statements [message #610797 is a reply to message #610796] Mon, 24 March 2014 07:10 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Did you try the FULL OUTER JON I mentioned?

Previous Topic: How? - Create Check constraint - field must contain @ symbol
Next Topic: computing statistics at the schema level
Goto Forum:
  


Current Time: Fri Apr 26 05:02:23 CDT 2024