1

I am trying to pull ids from table where numbers in comma-separated string 1, are all in comma-separated string 2. The IN function gives me ids if any numbers match, but I want all from string 1 to match or that id is not shown in result.

$query = "SELECT teams FROM #__bl_teamcord WHERE u_id = ".$t_id." AND s_id = ".$sid." LIMIT 1";
    $db->setQuery($query);
    $tcteams = $db->loadResult();


$query = "SELECT r.id FROM  #__bl_regions as r WHERE (NOW() between r.start_date and r.end_date) AND r.s_id = ".$sid."  AND (r.teams IN($tcteams))";
    $db->setQuery($query);
    $regions1 = $db->loadResultArray();
user1071915
  • 99
  • 3
  • 12

1 Answers1

2

Log story short, No MySQL can not split your string and try to do an IN clause. But there is a way around it. And here is the reference. http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/

Original Reference: Can Mysql Split a column?

Community
  • 1
  • 1
Churk
  • 4,556
  • 5
  • 22
  • 37