Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    Echo distinct MySQL columns values?

    Any way to echo distinct MySQL column values? I can only see COUNT(DISTINCT column). Example:

    • Red
    • Blue
    • Green
    • Blue
    • Blue


    Would echo as:

    • Red
    • Blue
    • Green
    Leonard Whistler

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    remove the count.

    Code:
    select distinct columnname from yourtablename
    note that will only work for single columns, DISTINCT is not a function and works across all columns in a row.

    for instance if you had

    color1 and color2 as your columns and had the following values:

    Orange Red
    Orange Blue
    Orange Green
    Red Orange
    Green Blue

    all of those rows are distinct from one another so
    Code:
    select distinct color1, color2 from yourtablename
    would return all of those rows.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Thanks guelphdad........The code is working.
    Leonard Whistler


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •