meow meow - 12 days ago 5
PHP Question

how to avoid repeation using group_concat() in MYSQL query

i need help i tried everything but nothing happen don't know what happen here
This is my db structure :

Below is my query

$q = "select distinct section_permissions.user_id ,section_permissions.assigned_for , u1.f_name as first , u1.l_name as last , u2.f_name as name1 , u2.l_name as name2 from section_permissions join users u1 on ( u1.user_id = section_permissions.user_id ) join users u2 on ( u2.user_id = section_permissions.assigned_for ) where section_permissions.user_id != 1 and assigned_for = ".(isset($_POST['assigned_for']) ? $_POST['assigned_for'] : 0);
$check = $this->section_permission_model->q($q);


same on march if i assign different section_id to different user_id
then also it combines i don't want that

please help me it display same as insert in db
and if user_id =4 is assigned two section then display as 1,2 only on that month not always

Answer

You need to use the DISTINCT option with GROUP_CONCAT like:

GROUP_CONCAT(DISTINCT col_name);
Comments