How to find out unique records in any table without using DISTINCT keyword and many more

 
My Tech Channel link:- https://www.youtube.com/oracleshooter
 
--====================================================
How to find out unique repords in any table without using DISTINCT keyword
--====================================================
 
select * from   XX_EMP_DISTINCT_TL
 

EMPNO

ENAME

JOB

MGR

HIREDATE

SAL

COMM

DEPTNO

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

7521

WARD

SALESMAN

7698

22-Feb-81

03-Jun-03

500

30

7499

ALLEN

SALESMAN

7698

20-Feb-81

18-May-04

300

30

 
 
INSERT INTO XX_EMP_DISTINCT_TL
select * from XX_EMP_DISTINCT_TL where rownum <4
 
 
INSERT INTO XX_EMP_DISTINCT_TL
select * from XX_EMP_DISTINCT_TL where rownum <2
 
 
--========
Method :- 1
--========
 
select  * from XX_EMP_DISTINCT_TL
 
select DISTINCT * from XX_EMP_DISTINCT_TL
 
select DISTINCT A.* from XX_EMP_DISTINCT_TL A
 
--========
Method :- 2
--========
 
select * from XX_EMP_DISTINCT_TL
 
select UNIQUE * from XX_EMP_DISTINCT_TL
 
--========
Method :- 3
--========
 
select * from XX_EMP_DISTINCT_TL
 
select * from XX_EMP_DISTINCT_TL
GROUP by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO
 
 
 
 
 
 
--========
Method :- 4
--========
 
select * from XX_EMP_DISTINCT_TL
union
select * from XX_EMP_DISTINCT_TL
 
 
--========
Method :- 5
--========
 
select * from XX_EMP_DISTINCT_TL
union
select NULL EMPNO , NULL ENAME   , NULL JOB    , NULL MGR     , NULL HIREDATE , NULL SAL   , NULL COMM , NULL DEPTNO from XX_EMP_DISTINCT_TL where 1=2
 
 
select * from XX_EMP_DISTINCT_TL
union
select NULL EMPNO , NULL ENAME   , NULL JOB    , NULL MGR     , NULL HIREDATE , NULL SAL   , NULL COMM , NULL DEPTNO from DUAL where 1=2
 
 
 
--========
Method :- 6
--========
 
select * from XX_EMP_DISTINCT_TL
INTERSECT
select * from XX_EMP_DISTINCT_TL
 
 
 
--========
Method :- 7
--========
 
select * from XX_EMP_DISTINCT_TL
MINUS
select NULL EMPNO , NULL ENAME   , NULL JOB    , NULL MGR     , NULL HIREDATE , NULL SAL   , NULL COMM , NULL DEPTNO from XX_EMP_DISTINCT_TL where 1=2
 
 
select * from XX_EMP_DISTINCT_TL
MINUS
select NULL EMPNO , NULL ENAME   , NULL JOB    , NULL MGR     , NULL HIREDATE , NULL SAL   , NULL COMM , NULL DEPTNO from DUAL where 1=2
 
 
--========
Method :- 8
--========
 
select
EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO,
 row_number ()
 over (Partition by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO order by rownum) Record_Count
from XX_EMP_DISTINCT_TL
 

EMPNO

ENAME

JOB

MGR

HIREDATE

SAL

COMM

DEPTNO

RECORD_COUNT

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

1

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

2

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

3

7499

ALLEN

SALESMAN

7698

20-Feb-81

18-May-04

300

30

1

7499

ALLEN

SALESMAN

7698

20-Feb-81

18-May-04

300

30

2

7521

WARD

SALESMAN

7698

22-Feb-81

03-Jun-03

500

30

1

7521

WARD

SALESMAN

7698

22-Feb-81

03-Jun-03

500

30

2

 
 
select * from (
select --rownum,                                                                                                                             
EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO,
 row_number ()
 over (Partition by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO order by rownum) Record_Count
from XX_EMP_DISTINCT_TL ) AA
where AA.RECORD_COUNT = 1
 
 
--========
Method :- 9
--========
 
select
EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO,
 RANK()
 over (Partition by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO order by rownum) Record_Count
from XX_EMP_DISTINCT_TL
 

EMPNO

ENAME

JOB

MGR

HIREDATE

SAL

COMM

DEPTNO

RECORD_COUNT

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

1

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

2

7369

SMITH

CLERK

7902

17-Dec-80

10-Mar-02

 

20

3

7499

ALLEN

SALESMAN

7698

20-Feb-81

18-May-04

300

30

1

7499

ALLEN

SALESMAN

7698

20-Feb-81

18-May-04

300

30

2

7521

WARD

SALESMAN

7698

22-Feb-81

03-Jun-03

500

30

1

7521

WARD

SALESMAN

7698

22-Feb-81

03-Jun-03

500

30

2

 
 
select * from (
select --rownum,
EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO,
 RANK()
 over (Partition by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO order by rownum) Record_Count
from XX_EMP_DISTINCT_TL ) AA
where AA.RECORD_COUNT = 1
 
 
--========
Method :- 10
--========
 
select * from XX_EMP_DISTINCT_TL
 
select  * from XX_EMP_DISTINCT_TL
GROUP BY EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO
 
select MIN(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO
 
select * from XX_EMP_DISTINCT_TL
WHERE ROWID in ( select MIN(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO  )
 
 
--========
Method :- 11
--========
 
select MAX(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO
 
select * from XX_EMP_DISTINCT_TL
WHERE ROWID in ( select MAX(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME   , JOB    , MGR     , HIREDATE , SAL   , COMM , DEPTNO  )
 

Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor