SQL - Join two fields in the same table to a single field in another table -
i'm working on way lookup description code appears in 2 fields of same table.
the table/field names :
contacts name, group_1 , group_4 lookup lookup_id, lookup_name contact.group_1 , contact.group_4 both refer values in lookup.lookup_id , need resolved corresponding name values in lookup.lookup_name.
how can connect both fields lookup table , have them bring respective lookup_name values ?
left join contacts lookup twice. once group_1 , once group_2. left join instead of inner join, may have contact without 2 groups.
select c.name, g1.lookup_name, g2.lookup_name contacts c left join lookup g1 on g1.lookup_id = c.group_1 left join lookup g2 on g2.lookup_id = c.group_4
Comments
Post a Comment