0

I have an object in the table column saved using JSON.stringify and it looks like this:

[{
    "id": 1,
    "uID": 10
}, {
    "id": 2,
    "uID": 10
}, {
    "id": 3,
    "uID": 94
}]

I need a query that will check if a given column contains values e.g.

  • I want uID = 10 and id = 2 will return
  • I want uID = 10 and id = 5 will not return it
  • I want uID = 10 and id = 2, uID = 94 and id = 0 will not return it (because uID = 94 and id = 0 is not here)
1
  • What have you tried so far? Where are you stuck? Commented Nov 19, 2019 at 15:35

3 Answers 3

1

Unless you are querying programmatically where you can parse the JSON and then do the logic, I would recommend something like this:

SELECT * FROM Table WHERE Column LIKE '%"id": 1,"uID": 10%'

The LIKE keyword allows us to use wildcards (%) but still do an exact text match for what we define.

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

Comments

0

Add a wildcard in the middle, but note that order matters with this strategy.

SELECT * FROM Table WHERE Column LIKE '%"id": 1%"id": 2%'

Comments

0

I need it to work backwards too:] e.g. I have

[{
    "id": 1,
    "uID": 10
}, {
    "id": 2,
    "uID": 55
}, {
    "id": 3,
    "uID": 94
}]

SELECT * FROM Table WHERE Column LIKE '%"uID": 55%"uID": 94%' <- will be working

SELECT * FROM Table WHERE Column LIKE '%"uID": 94%"uID": 55%' <- will be not working

Does not work "back"

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.