Given the following table (
PersonId CoupleId ------------------- 1 2 2 1 3 (null) 4 5 5 4
By writing a query similar to this
Select count(?) from people_table
I expect 2 as count result
I think the simplest method is:
select count(*) from people_table where PersonId < CoupleId ;
Why does this work? Well, two people in a couple have different ids. One of them must be smaller than the other and this counts one of them.
This also filters out
Note: This assumes that your data is well-formed -- that is, both persons in a couple are in the table as separate rows.