Solved

Request a high efficient query

Posted on 2011-09-27
4
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

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 77

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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

738 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