Distinct Count

Posted on 2005-05-05
Last Modified: 2010-03-19

I have a table which holds various details i need to count the amount of times an item appears.  But i need to only count the item against 1 id  - i think i'm confusing things - so here's what i need

Logid                  LogType                     Info
035621                  FILEH                       Log on
035622                  FILE                         Log on
035622                  FILE                         Check Something
035622                  FILE                         Log off
035623                  FILEH                       Log off
035623                  FILEH                       Log on
035624                  FILEH                       Log on

So basically i need to count how many times File and FileH appear against the Logids

So the result i need from this is

Logtype                             Count
FILE                                     1
FILEH                                   3


Question by:cafferm
    LVL 33

    Expert Comment

    //r u asking for this ?
    select count(*),logtype
    from tablename
    group by logtype
    LVL 33

    Accepted Solution

    select count(distinct logid),logtype from table
    group by logtype;

    Author Comment

    Thats it thanks

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Via a live example, show how to shrink a transaction log file down to a reasonable size.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now