I have a SQL squery,
SELECT * FROM gr_person as GR
INNER JOIN ADDRESS ON GR.address_code = ADDRESS.address_code
JOIN dbo.GR_PERSON_TYPES GPT
ON GR.person_type = GPT.person_type
WHERE event_number = '101000008'
ORDER BY GPT.type_key
That returns
GR.event_number, GR.person_type, GR.customer_code, GPT.type_key, GPT.event_type, GPT.person_type
101000008 Wife 10001 3 2 Wife
101000008 Wife 10001 4 3 Wife
I want this query to return only ONE ROW if the GR.PERSON_TYPE is SAME as in this case.
I tried adding a group by GR.PERSON_TYPE, but can’t help it.
Can somebody tell me how to do it?
You can group by
person_typeto get one result for the groupWife, but you will need to aggregate or exclude your other columns.For instance, if you only want one record for
Wife, what should the value fortype_keyandevent_typebe? If you want to see the maximum or averageevent_typefor your Wife group, you could usemax(event_type)oravg(event_type). The documentation for your DBMS should be able to explain all the aggregate functions for you.