Counting the records

  • Hi All ,

     

    I need to count the records in the table but the duplicate record should be counted once.

     

    Ex:

    A                       B

    1                       hhhhh

    1                       mmmm

    1                       kjkjj

    2                        332

    3                       dsd

    3                       asdfsa

     

    Now if we count the record the result should be count=3 not count=6

    from

    Killer

     

     

  • Try this

    select distinct ID from table_name

    query returns :

    A

    1

    2

    3

  • Or this:

    select count(distinct A) from table_name

    It returns: 3

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Sorry not to mention that the ERP application(Naviosion Axapta) we are using do not support distinct function.

    so do we have another way of doing this

    from

    killer

  • Could you create a distinct view and run your query against that?

    If not, please mention what other restrictions you have to work round.

    Regards

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Erm, how about:

    select count(*) from (select A from table_name group by A) a

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Hi Ryan,

     

    Thanx It worked like magic.

    Thanx to all of u.

     

    from

    Killer

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply