• GilaMonster (8/24/2016)


    Luis Cazares (8/24/2016)


    Also, using DISTINCT is expensive. In this case, you should try using GROUP BY.

    Which will behave exactly the same as the DISTINCT. Since he wants distinct values, DISTINCT is the correct thing to use.

    Not really. The results will be the same, but the process won't.

    Using DISTINCT, it will generate the concatenated values and then remove duplicates. Using GROUP BY, it will remove the duplicates and the concatenate the values. It can be a big difference in performance, depending on the rows.

    On most cases, I'd agree with the premise of using DISTINCT to get unique rows, but not for this.

    EDIT: An alternative, is to use the method shown on the article to get unique key values and then concatenate.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2