0

I have a Database that looks like this (unfortunately cannot be changed)

patients (table)
name    |   companies
-----------------------
Form 1  |     [8,3]
Form 2  |     [8]

I want to select every form with an assignment of 8 so I tried this:

SELECT * FROM patients WHERE FIND_IN_SET(patients, 8)

But it's not working, I tried another test in a sample database and if the [ and ] is removed it works just fine, unfortunately the [ and ] cannot be removed in the live database (this data is stringified from JSON)

1

1 Answer 1

4

You can use REPLACE() to strip [ and ] brackets before using companies in FIND_IN_SET.

SELECT * 
  FROM patients 
 WHERE FIND_IN_SET(8, REPLACE(
                        REPLACE(
                          companies, 
                        '[', ''), 
                      ']',''))

SQLFiddle

Please refer this question for the same scenario.

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

2 Comments

Does this modify the values in the db?
@Jordash No, it should not.

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.