MS SQL Server 2000:
I'm trying to get a list of distinct columns, but I also need the primary key. I thought something like this might work:
but I get an error "Column 'vCmnPerson.CmnPersonPK' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."Code:SELECT a.CmnPersonPK, b.LastName, b.FirstName, b.MiddleName, b.DOB FROM vCmnPerson a INNER JOIN (SELECT CmnPersonPK, LastName, FirstName, MiddleName, DOB FROM vCmnPerson GROUP BY LastName, FirstName, MiddleName, DOB) AS b ON a.CmnPersonPK = b.CmnPersonPK
Been trying and searching, can't figure it out. How do I get a list where those four columns are distinct, but also retrieve the PK?
Thanks,
Mike




Reply With Quote