0

I can find whit this query

SELECT * 
FROM Table 
WHERE CODE_DESC = '{"title:\["1","2","3"\]"}'

But, I can't find this query

SELECT * 
FROM Table 
WHERE CODE_DESC LIKE '%{"title:\["1","2","3"\]"}%'

What is different?

I tried like this:

SELECT * 
FROM Table 
WHERE CODE_DESC LIKE '% {"title:\["1","2","3"\]"} %'

SELECT * 
FROM Table 
WHERE CODE_DESC LIKE '%{"title:\["1","2","3"\]"}%'

but, I can't solve the issue

Thom A
  • 88,727
  • 11
  • 45
  • 75
Jeremy
  • 3
  • 2
  • 4
    which RDBMS are you using MySQL,SQL Server,postgresql. tag it correctly – RF1991 Apr 04 '22 at 06:01
  • Don't use LIKE to search within JSON values in the first place, this is a horrible idea. Use the JSON functions of your database to extract and compare the values you're looking for. – Tomalak Apr 04 '22 at 06:28
  • I using sql-server, and It's not real json data. just string like json in column – Jeremy Apr 04 '22 at 07:42
  • In sql-server you need to escape the `[]` in a like, see: [LIKE (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15) – Luuk Apr 04 '22 at 07:48
  • Why not use SQL Server's actual JSON tools to parse your JSON instead? Then you might not need to use a `LIKE` at all. – Thom A Apr 04 '22 at 08:14

1 Answers1

1

In sql-server you need to escape the [] in a like, see: LIKE (Transact-SQL)

This works too (replacing the [ by and _, which matches any single character:

SELECT * 
FROM Table 
WHERE CODE_DESC LIKE REPLACE('%{"title:\["1","2","3"\]"}%','[','_')
Luuk
  • 12,245
  • 5
  • 22
  • 33