How to remove duplicates for below scenario

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anjalive
    New Member
    • Jul 2015
    • 4

    How to remove duplicates for below scenario

    Hello,

    Empid Empname Depno
    1111 yyyyy 10
    2222 zzzzz 10
    1111 yyyyy 10

    Select distinct empname from employee where deptno=10;

    With this stmt i can get empnames which are unique.
    Outpu as:
    1111 yyyy 10
    2222 zzzz 10

    But The question here is:

    If entire row is duplicated then, distinct will work to remove duplicates.
    If we have table like this:

    Ip_Address Status Date
    x.x.x.x Success 8/5/15
    y.y.y.y NoAccess 8/4/15
    x.x.x.x NoAccess 8/6/15

    Here x.x.x.x is duplicated. I can delte this with distinct. How to remove this kind of duplicates ??

    Thank you.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need a unique key in the table. Then you can select by the field that should be distinct and return the min or max key, that will tell you which row to delete.

    Comment

    Working...