Retrieve duplicate value

I have table p_id
I want to have duplicate value from column cid(1,3)
where did=$value and ($value=1,2)
±----±------+
| cid|did |
±—±–+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 3 | 1 |
| 1 | 2 |
±----+

I tried to make sql statemet like this

foreach($did as $value)
  	  {
   	  $sqls="SELECT contact_id FROM contactdeb where data_no =$value group by contact_id " ;

but it retrieved all
any help?

You are missing the HAVING clause to check for multiple occurrances, and don’t run a query for each value of did, use IN instead:


$didlist = implode(',', $did);
$sqls = "
  SELECT cid 
  FROM p_id
  WHERE did IN ($didlist)
  GROUP BY cid
  HAVING COUNT(*) > 1
";

thanks thanks thanks
:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: