MYSQL output unique values

Discussion in 'PHP' started by webmoney, Feb 15, 2009.

  1. #1
    I have feed with entries where each entry (row) has 7 different categories.

    I need to list all these categories, these are repeating often so I need list only of unique categories.

    Categories are category1....category7 and there is at least 1 value for each row.

    I found only this function http://cz.php.net/manual/en/function.array-unique.php and also GROUP BY but I am not sure how to combine it to get simple output of all categories in DB.
     
    webmoney, Feb 15, 2009 IP
  2. mac83

    mac83 Active Member

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #2
    SELECT DISTINCT category_name from table_name WHERE ....

    DISTINCT will fetch values which are unique...
     
    mac83, Feb 15, 2009 IP
  3. webmoney

    webmoney Well-Known Member

    Messages:
    1,119
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    155
    #3
    But I would have to use something like:
    SELECT DISTINCT category1,category2,...,category7 from table_name

    I need to get all entries from categoryX and than select those uniques.
     
    webmoney, Feb 15, 2009 IP
  4. webmoney

    webmoney Well-Known Member

    Messages:
    1,119
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    155
    #4
    The output would be just text or another table with all unique categories from first table.

    Anyone?
     
    webmoney, Feb 16, 2009 IP
  5. webmoney

    webmoney Well-Known Member

    Messages:
    1,119
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    155
    #5
    OK, could not wait and I spent whole day playing around and here is what I needed.

    I hope it will be helpful to someone since I found few similar questions like this.
     
    webmoney, Feb 16, 2009 IP