Codeigniter Database Joins two columns based on multiple values

I want to help with the following query: -

    $this->db->select('nbr.*, dm.dma, st.abbrev as state,unit.size_title as ad_size_title,unit_u.size_title as ad_unit_title,di.size_title as ad_di_title,color.title as color_title');
$this->db->from('default_new_buy_request as nbr');
$this->db->join('default_dmadata as dm', 'nbr.dma_id = dm.id', 'left');
$this->db->join('default_states as st', 'nbr.state_id = st.id', 'left');

      

nbr.dma_id

contains multiple comma (',') separated values ​​and compares to all dm.id

in default_dmadata

, but here it is just comparing only one value with dm.id

. In short, I need a function like explode () to compare each value against the second column.

+3


source to share


1 answer


You may try?

Usage If Values ​​In Comma



In MYSQL try it with Codeigniter

LEFT JOIN default_dmadata dm ON FIND_IN_SET(dm.dma_id, dm.id)

      

+1


source







All Articles