I am writing this query to find duplicate CTN Records in table1. So my thinking is if the CTN_NO appears more than twice or higher , I want it shown in my SELECT * statement output on top.
I tried the following sub-query logic but I need pulls
SELECT *
table1
WHERE S_IND='Y'
and CTN_NO = (select CTN_NO
from table1
where S_IND='Y'
and count(CTN_NO) < 2);
order by 2
Using:
…will show you the
ctn_novalue(s) that have duplicates in your table. Adding criteria to the WHERE will allow you to further tune what duplicates there are:If you want to see the other column values associated with the duplicate, you’ll want to use a self join: