0

I would like to ask how to filter a table by column with array value, I have a column "categories" that can have a value like [1,2,3] now I want to filter the table with that table like SELECT * FROM TABLE WHERE CATEGORIES = 2,

I also tried LIKE but it seems like it is not the proper way to do it, any opinions and suggestions would be appreciated.

6
  • Have you tried the SQL IN Operator? Commented Oct 24, 2017 at 6:42
  • @rmjoia yes sir but no luck Commented Oct 24, 2017 at 6:44
  • So the categories column value is "1,2,3" or "[1,2,3]"? Commented Oct 24, 2017 at 7:13
  • @Neodan its [1,2,3] since it is an array Commented Oct 24, 2017 at 9:05
  • @Hannyson it's not an array, it's just a text. It's mean that your DB schema is realy bad (-; Commented Oct 24, 2017 at 9:11

1 Answer 1

5

It is not recommended way to store comma separated values in Column which needs to be filtered for queries.

You can use normalization and introduce relationship tables for categories and category_ids to be stored in different tables, then you can use join and where clause to achieve your results.

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

1 Comment

Will follow your advise then Sir Thank you.

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.