SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do i query a db and only count unique items, so in the feild "name"

    if eric accures twice, it will only count the first one, and skip the rest
    ___________________________________

    << Footer under construction >>

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use GROUP BY in the sql

    PHP Code:

    $sql 
    "SELECT author FROM table GROUP BY author";
    $result mysql_query($sql);
    $num_authors mysql_num_rows($result);
    echo(
    "$num_authors"); 
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I think undecided is after DISTINCT

    SELECT DISTINCT name from tablename
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddy... I use this same basic code on my sites with no problem.... yet I have never learned what DISTINCT does... could you ulaberate on it a bit, or point me into a tutorial/manual online?
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DISTINCT does what it sounds like: it selects distinct entries.

    SELECT DISTINCT name FROM people

    That should select only one of each name from the "people" table - IE: if two people are named Eric, you'll only have on returned.

    Here are is a quick link:

    - http://www.mysql.com/doc/D/I/DISTINCT_optimization.html

  6. #6
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about using the LIMIT with either DISTINCT or GROUP BY? I've tried this... but no luck yet...

    oh well... thanx for your time Commish.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •