Solved

count problem in oracle SQL

Posted on 2013-11-05
4
437 Views
Last Modified: 2013-11-18
I have table a and table b with column x in both tables.

In table b the column x  can have the same value on several rows while in table a column x only have unique values.

I want to count the number of rows in table a where the same value exists on more than 10000 rows in table b!
0
Comment
Question by:bear_2013
  • 2
  • 2
4 Comments
 
LVL 31

Expert Comment

by:awking00
Comment Utility
select x, count(*)
from tableb b
where exists
(select 1 from tablea a
 where a.x = b.x)
group by x
having count(*) > 10000;
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
select count(*) from A
where X in (select X from B group by X having count(*) > 10000)
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
awking00,  I think you have the tables backwards.  Other than that, the exists method should also work


bear_2013 - both of our methods assume X is NOT NULL.  Is that a safe assumption?
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
I seem to have been thinking backwards a lot lately :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now