Get name of all term which is duplicate using Mysql

Question

I am coding something to get all duplicate term which has duplicate name using MySql query. The issue I have currently is I am getting the records in a single occurrence I need all data which has same name.

I am running this query.

SELECT a.*,COUNT(name) AS occurrences 
            FROM wp_terms AS a 
            INNER JOIN wp_term_taxonomy AS b ON a.term_id = b.term_id  
            WHERE b.taxonomy = "ticker"
            GROUP BY a.name HAVING occurrences > 1

Current result

[0] => stdClass Object
        (
            [term_id] => 13872
            [name] => AAV
            [slug] => aav
            [term_group] => 0
            [occurrences] => 2
        )

Expected result

[0] => stdClass Object
            (
                [term_id] => 13872
                [name] => AAV
                [slug] => aav
                [term_group] => 0
                [occurrences] => 2
            )
    [1] => stdClass Object
            (
                [term_id] => 13873
                [name] => AAV
                [slug] => aav-2
                [term_group] => 0
                [occurrences] => 2
            )

Any ideas on that?

0
, , , Tejas Gajjar 2 years 2019-12-24T07:19:34-05:00 0 Answers 111 views 0

Leave an answer

Browse
Browse