Solved

Request a high efficient query

Posted on 2011-09-27
4
202 Views
Last Modified: 2012-06-21
Have a table T with the following data
T (c1 number(10), c2 varchar2(10))

c1    c2
1      B
1      C
2      A
3      D
4      A
4      A
5      A
5      B
6      C
6      A
6      D
7      E
8      B
8      C
....

Now want to get all C1 with only C2=A (single and duplicates). For the above example,

Want to get the records:
c1
2
4

Since C2 in all of the records are 'A', they are selected..

0
Comment
Question by:jl66
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 450 total points
ID: 36713751
Try this:

Select c1 from table where c1='A'
Minus
Select c1 from table where c2 !='A';
0
 
LVL 16

Assisted Solution

by:Swadhin Ray
Swadhin Ray earned 50 total points
ID: 36714565
Try the below one as I think slightwv's typo mistake for c1 in place of c2:

Select c1 from table where c2='A'
Minus
Select c1 from table where c2 !='A';
Posted via EE Mobile
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36716417
Thanks for the catch on the typo.
0
 

Author Closing Comment

by:jl66
ID: 36717557
The query is quite efficient. Thanks a lot for both.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

762 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

22 Experts available now in Live!

Get 1:1 Help Now