prewky
prewky

Reputation: 25

JSON_SEARCH negation in MySQL

whats the MySQL sql comand equivalent of this :
select id where not json_search(example,'one','0')
it selects only elements where there is no '0' in the json array of the column named example.

Upvotes: 1

Views: 532

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562270

The json_search() function returns NULL when it finds no match. It does not return false. You can't use NOT to negate it, because NULL is not false. The negation of NULL is still NULL.

You can query it this way:

select id from ...mytable... 
where json_search(example, 'one', '0') is [not] null;

Use is null if you want cases where no match is found.

Use is not null if you want cases where a match is found.

Upvotes: 2

Related Questions