Skip to Main Content
  • Questions
  • Selecting rows that have specific value

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Dev.

Asked: May 02, 2017 - 5:43 pm UTC

Last updated: May 04, 2017 - 3:40 pm UTC

Version: 11

Viewed 1000+ times

You Asked

Hello,
I am asking for help due to time constraint. With the example table given below, the requirement is to select Asset that has Src of only 10. For example, the output that I would expect from this table below would be Assets = 2000, 4000

Asset Src Date
1000 10 01-jan-2017
1000 11 01-mar-2017
1000 34 01-feb-2017
2000 10 10-jan-2017
3000 10 10-jan-2017
3000 11 11-feb-2017
4000 10 14-feb-2017
5000 11 15-mar-2017
5000 34 20-apr-2017

Assets 2000 and 4000 are the only ones to have just Src 10. The criteria is that I need to see assets that has a Src of only 10 and not anything else. That is why I do not want to see other assets.

and Connor said...

Request for Info:

Hmmm... I see FOUR rows with the SRC being 10, so what makes assets 2000, 4000 different from the others. What is the other criteria you are expecting ?

=====================

Just a tip for future questions - give us the data as *SQL*, ie, create table plus insert statements like I've done below

SQL> create table t ( asset int, src int, d date );

Table created.

SQL>
SQL>
SQL> insert into t values (1000,10,'01-jan-2017');

1 row created.

SQL> insert into t values (1000,11,'01-mar-2017');

1 row created.

SQL> insert into t values (1000,34,'01-feb-2017');

1 row created.

SQL> insert into t values (2000,10,'10-jan-2017');

1 row created.

SQL> insert into t values (3000,10,'10-jan-2017');

1 row created.

SQL> insert into t values (3000,11,'11-feb-2017');

1 row created.

SQL> insert into t values (4000,10,'14-feb-2017');

1 row created.

SQL> insert into t values (5000,11,'15-mar-2017');

1 row created.

SQL> insert into t values (5000,34,'20-apr-2017');

1 row created.

SQL>
SQL> select * from t t_main
  2  where src = 10
  3  and not exists
  4    ( select * from t
  5      where t.asset = t_main.asset
  6      and  src != 10 );

     ASSET        SRC D
---------- ---------- ---------
      2000         10 10-JAN-17
      4000         10 14-FEB-17





Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Dev N, May 04, 2017 - 2:37 pm UTC

Thank you very much. The problem was that I was including the date in the subquery which was skewing my results.
Chris Saxon
May 04, 2017 - 3:40 pm UTC

Great, glad we helped you resolve this!