Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple solution grouping? Perhaps?

Status
Not open for further replies.

robdunfey

Technical User
Apr 26, 2002
110
GB
I run to queries. The first query returns:

A
B
B
C

The second query returns:

A
A
B
B
C

I am trying to write a third query that compares results from query 1 & 2 to give:

B

Because if you match the results of 1 & 2 B is the letter that completely matches? I am new to Oracle but am quite bambozzled by this.

Rob
 
<select statement 1> INTERSECT <select statement 2>, is one possibility. Take a look at the Oracle SQL Reference Manual for more info.
 
No - this would give you
A
B
C

Rob - why doesn't C match in both queries (I assume by &quot;completely matches&quot; you mean the same number of occurrences; if this isn't the case, please explain what you really mean).

SELECT letter_column FROM
(SELECT col1 letter_column, count(*) rowcount
FROM table1
GROUP BY col1
INTERSECT
SELECT col1, count(*)
FROM table2
GROUP BY col1);

should give you what you're looking for.
 
bppbme,

Thanks for the reply. I had thought of the select statement but this did not work. I end up with:

ABBC which makes sense. How do I get just B?
 
Whoops, wasn't paying attention to the example results. Sorry!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top