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();
2
  • are you trying to do this? "1,2,3" = "1,2,3" or 1 in ["1,2,3".split(",")] Commented Apr 3, 2012 at 17:23
  • Where 1,2,3 are in 5,16,2,78,1,54,34,3 .....May not be in 1,2,3 same order but each value is in second table. Commented Apr 3, 2012 at 17:35

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.