0

I have a column in a SQL table that contains json lists as text.

I want to find all the rows that have [7] in the column. So I have something like the following

SELECT col1, col2 FROM tbl1 WHERE col2 LIKE '[7]'

However this comes back with nothing (though I can see rows when I inspec the table that have that in the field).

Stranger still, if I try editing the query to the following

SELECT col1, col2 FROM tbl1 WHERE col2 LIKE '%[7]%'

It will find the rows that have [7], but it will also get rows that clearly (I think) violate that pattern, i.e. rows that have [1,7]

Is the square bracket something special that I'm not aware of?

sedavidw
  • 11,116
  • 13
  • 61
  • 95

1 Answers1

2

Try something like

SELECT col1, col2 FROM tbl1 
WHERE col2 LIKE  '%\[7]%' ESCAPE '\'
M.Ali
  • 67,945
  • 13
  • 101
  • 127