Select and display only duplicate records in mysql

后端 未结 12 2095
南旧
南旧 2020-12-08 06:56

This question is pretty simple I for some reason cant get the proper result to display only the duplicate records

Table   : Paypal_ipn_orders
id                      


        
12条回答
  •  既然无缘
    2020-12-08 07:52

    Hi above answer will not work if I want to select one or more column value which is not same or may be same for both row data

    For Ex. I want to select username, birth date also. But in database is username is not duplicate but birth date will be duplicate then this solution will not work.

    For this use this solution Need to take self join on same table/

    SELECT  
        distinct(p1.id),  p1.payer_email , p1.username, p1.birth_date
    
    FROM 
        paypal_ipn_orders AS p1 
    
    INNER JOIN paypal_ipn_orders AS p2 
    
    ON p1.payer_email=p2.payer_email
    
    WHERE 
    
    p1.birth_date=p2.birth_date
    

    Above query will return all records having same email_id and same birth date

提交回复
热议问题