SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count unique records

    I have a table where each row contains a boolean and a foreign key to another trecord in another table.

    I want to know how many distinct foreign keys have false as the boolean - something like this:

    Code:
    SELECT  COUNT(
    	SELECT	DISTINCT Table.RecordID
    	FROM	Table
                 WHERE Table.Bool = 0)
     AS UniqueRecordCount
    how would i achieve this?

    cheers

    monkey
    monkey - the rest is history

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    SELECT  COUNT(DISTINCT Table.RecordID) AS UniqueRecordCount
    FROM	Table
    WHERE Table.Bool = 0

  3. #3
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Code:
    SELECT  COUNT(DISTINCT Table.RecordID) AS UniqueRecordCount
    FROM	Table
    WHERE Table.Bool = 0


    2 people, 2 days - every combination except that one!!

    Thanks muchly - we are busy kicking ourselves in the office!
    monkey - the rest is history

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Don't kick too hard... there's a party tonight!


Bookmarks

Posting Permissions

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