SQL JOIN help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • midwesthills@hotmail.com

    SQL JOIN help

    I have two tables (simplified example):

    table person
    PK data
    1 A
    2 B
    3 C
    4 D

    table choice
    PK FK
    1 1
    2 1
    3 1
    4 2
    5 2
    6 2

    I need to count the total number of people that made a choice. Each
    person should only be counted once, regardless of how many choices they
    have.

    Thanks in advance for the help!

  • Lee Tudor

    #2
    Re: SQL JOIN help

    provided that referential integrity holds between the two tables. (No choice
    records for persons who dont exist)

    SELECT Count(DISTINCT FK) FROM Choice

    Mr Tea
    <midwesthills@h otmail.com> wrote in message
    news:1108903210 .363952.145480@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    >I have two tables (simplified example):
    >
    > table person
    > PK data
    > 1 A
    > 2 B
    > 3 C
    > 4 D
    >
    > table choice
    > PK FK
    > 1 1
    > 2 1
    > 3 1
    > 4 2
    > 5 2
    > 6 2
    >
    > I need to count the total number of people that made a choice. Each
    > person should only be counted once, regardless of how many choices they
    > have.
    >
    > Thanks in advance for the help!
    >[/color]


    Comment

    Working...