i would like to know how to create a flag for duplicate rows in a table.for example : if i get duplicate rows it will show me 1 and if i dont get any duplicate rows,it will display 0
i tried the following for this test table i have used to check whether or not it will work
SQL> select * from t_flag 2 / EMP_NAME EMP_NO DEPT -------------------------------------------------- --------- -------------------- ROBI 1 AGRO ROBI 1 AGRO BORIS 2 IT SID 3 VET BORIS 2 IT select t_flag.*, (case when row_number() over (partition by emp_name,emp_no,dept order by emp_name) = 1 then 0 else 1 end) as GroupFlag from t_flag SQL> / EMP_NAME EMP_NO DEPT GROUPFLAG -------------------------------------------------- --------- -------------------- --------- BORIS 2 IT 0 BORIS 2 IT 1 ROBI 1 AGRO 0 ROBI 1 AGRO 1 SID 3 VET 0 what i would like to get from the result is : 1 for duplicate rows and 0 for non-duplicate rows
thanks!
COUNT()analytic function instead ofROW_NUMBER()