Select distinct question
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
0