0

My team has stored array data as a string in MySQL like below

["1","2","22","11"]

How can we select data from the table where the column contains a certain branch number.

Example of table

sno | Name | Branch 
1.  | Tom. | ["1","2","22"]
2.  | Tim. | ["1","2"]

Can you suggest a query to select all rows containing branch 2?

We tried using FIND_IN_SET() but that is not working as the double quotes and square brackets are also a part of string.

1
  • If you mean the column is type json this thread has a few suggestions stackoverflow.com/questions/36249828/… such as JSON_TABLE or JSON_CONTAINS. Not sure which (if any) is the best option performance wise . See example dbfiddle.uk/… Commented Mar 9, 2022 at 7:21

1 Answer 1

2

Use like:

select *
from mytable
where Branch like '%"2"%'
Sign up to request clarification or add additional context in comments.

1 Comment

Well if you're going to be logical about it ... (-;

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.