Skip to content
Advertisement

Select query where exists intersection of two list

I have one table that contains two columns:

  1. id (integer)
  2. list_colum (longtext) – contains json array (e.g. [1, 2, 3])

I want to select all records that have an intersection of my input list.

Let me explain:

My input is a list – [2, 3]

Pseudo code:

Is it possible to do this in SQL?

I am using the newest version of MariaDB.

Advertisement

Answer

Edit: The answer doesn’t give a true intersection: it only checks if the given JSON array is the intersection and not whether there is an intersection between it and the stored value.


JSON_CONTAINS should work:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement