0

I have a field in a table that contains 1,2,3, what I need is a way to check this field for a match with something like:

SELECT
  t1.something
FROM
  tblContent t1
WHERE
  1 IN (SELECT comma_delimited_string FROM tblAnother WHERE match=t1.ref)

Where 1 in the above query is the data I want to match in the 'comma_delimited_string' returned by the sub query.

This doesn't work and only returns a match if 1 is the first item in the subquery.

I've been reading about regular expressions, but have never used regular expressions in SQL.

If the comma_delimited_string contains 11,2,3 and not 1 then a match should not be returned, it should only match if the comma_delimited_string contains 1 or 1, or ,1

1
  • Should split up the values in another table. Commented Jan 7, 2016 at 2:52

1 Answer 1

1

Solved by using:

    SELECT
      t1.something
    FROM
      tblContent t1
    WHERE
      FIND_IN_SET(1, (SELECT comma_delimited_string FROM tblAnother WHERE match=t1.ref))
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.