SQL Language (MOSC)

MOSC Banner

Select distinct question

edited Feb 10, 2016 8:32AM in SQL Language (MOSC) 5 commentsAnswered ✓

11.2.0.4


SQL> drop table t1;



Table dropped.


SQL>  create table t1
  2       (emp_name varchar2(10),
  3        id   varchar2(4))
  4        ;


Table created.


SQL>   
SQL>  insert into t1
  2    values ('SCOTT 1','123A');


1 row created.


SQL>
SQL> insert into t1
  2    values ('SCOTT 2','123B');


1 row created.


SQL> 
SQL>
SQL> insert into t1
  2    values ('JONES 1','123C');


1 row created.


SQL>
SQL> insert into t1
  2    values ('JONES 2','123D');


1 row created.


SQL>  
SQL>  
SQL>   select count(emp_name), emp_name from
  2      (select substr(emp_name,1,5) emp_name from t1)
  3      group by emp_name;



COUNT(EMP_NAME) EMP_NAME
              2 JONES
              2 SCOTT


SQL>    

All good to here.  My conundrum is I also want to return an ID  where the ID matches any of the rows that matches the substring for that count, example

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center