Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2014
    Posts
    35

    Unanswered: Count without including duplicates

    I have a php mySQL database which records clients visits to a free advice clinic. There is a ‘matters’ table which, amongst others, has fields:
    matterid
    clientname
    visitdate

    I want to get totals from this (between certain dates but that isn’t an issue) but I only want to count a client once no matter how many different matters they have set up.

    If I use 'SELECT DISTINCT clientname' then I get a list with no duplicates but if I add 'count(*) as total' the total includes duplicates so is incorrect.

    How can I get round this?

  2. #2
    Join Date
    Feb 2014
    Posts
    35
    Sorry - I have worked this out now using COUNT(DISTINCT clientname) as total which seems to work fine. I do have a more complicated question though which I will add as a new post.

Posting Permissions

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