#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    31
    Rep Power
    3

    Count from a table


    Hi,

    I have a table which is :

    ID Type FamilyName
    peter Related muberry
    peter Non-Related jackson
    peter non-Related jackson
    tom non-Related murberry
    tom Related jackson

    I want to count how many non related family members each person has

    So the output should be

    peter jackson 2
    tom murberry 1


    Any ideas ?

    Regards
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,120
    Rep Power
    4274
    Code:
    SELECT id
         , familyname
      FROM daTable
     WHERE type = 'non-related'
    GROUP
        BY id
         , familyname
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo