I am having trouble with a mysql query. I want to get a unique pairing of names that share the same tenant_group_id number. All you need to know is that each tenant has a unique individual_tenant_id and up to two individual tenants share the same tenant_group_id.
SELECT t1.first_name, t2.first_name
FROM individualtenant t1
LEFT JOIN individualtenant t2 ON t1.tenant_group_id = t2.tenant_group_id
AND t1.individual_tenant_id != t2.individual_tenant_id
Right now this is giving me pairs but both ways, for example, it would return "John", "Melissa" and "Melissa", "John" but I only need a unique pairing.
EDIT: And if the individualtenant does not have a partner I need to have NULL in the second column.