SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast Patrick Lucas's Avatar
    Join Date
    Dec 2001
    Location
    Ohio
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySQL Query Question

    Hello,
    I have a simple mySQL table with the following columns: id and artist_id


    The ID column is the primary key. Is there anyway I can select all of the artist_id columns, but not have any of them repeat?

    Hope that makes sense


    Thanks!
    Patrick Lucas

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT DISTINCT artist_id FROM your_tablename;

  3. #3
    SitePoint Enthusiast Patrick Lucas's Avatar
    Join Date
    Dec 2001
    Location
    Ohio
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah. Hoped it'd be simple. Thanks!
    Patrick Lucas

  4. #4
    SitePoint Enthusiast Patrick Lucas's Avatar
    Join Date
    Dec 2001
    Location
    Ohio
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now... Is there any easy way to order the results by occurrence?
    Patrick Lucas

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you mean count each artist_id and sort them from most to least? this will do that:

    Code:
    SELECT COUNT(*) AS count, artist_id FROM table GROUP BY artist_id ORDER BY count DESC
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

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