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
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 |
select * from XX_EMP_DISTINCT_TL where rownum <4
select * from XX_EMP_DISTINCT_TL where rownum <2
Method :- 1
--========
Method :- 2
--========
Method :- 3
--========
GROUP by EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO
Method :- 4
--========
union
select * from XX_EMP_DISTINCT_TL
Method :- 5
--========
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
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
--========
INTERSECT
select * from XX_EMP_DISTINCT_TL
Method :- 7
--========
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
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
--========
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
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 --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
Method :- 9
--========
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
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 --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
Method :- 10
--========
GROUP BY EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO
WHERE ROWID in ( select MIN(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO )
Method :- 11
--========
WHERE ROWID in ( select MAX(ROWID) from XX_EMP_DISTINCT_TL GROUP by EMPNO , ENAME , JOB , MGR , HIREDATE , SAL , COMM , DEPTNO )
Comments
Post a Comment