Reputation: 99
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();
Upvotes: 1
Views: 2679
Reputation: 4637
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?
Upvotes: 2