Given a one-dimensional array named A of length X, and a two-dimensional array named B with x one-dimensional arrays inside of different lengths, I want to find out using SQL if all elements of A can be found in B, such that each sub-array in B contains 1 element from A, and all elements of A are divided evenly throughout B. It's not about putting elements into B but checking if the elements of A can already be found in B using these rules.

This sounds and is a bit complicated to explain, so I'll give some examples.

A=ARRAY[1,2,3] B=ARRAY[[2,3],[3,2],[1,4]]

In this case the SQL code would return TRUE, because 2 can be found in B[1], 3 in B[2] and 1 in B[3]. 3 can also be found in B[1], 2 in B[2] and again 1 in B[3], but it just matters that there is at least one way to do this, not which way it is.

A=ARRAY[1,2,5] B=ARRAY[[2,3],[3,2],[1,4]]

In this case the code would return FALSE; because 5 can not be found in any of the B sub-arrays.

A=ARRAY[1,2,4] B=ARRAY[[2,3],[3,2],[1,4]]

In this case the code would return FALSE, because both 1 and 4 are only in B[3], so whichever one is chosen for that sub-array, the other one can't be found anywhere else.

I hope these examples show what I want to achieve. It seems like it SHOULD be possible to do with a SELECT statement, but I am rather at a loss at how to achieve it. I also have a feeling that this should be a well-known programming problem, such that it has a name (like Knapsack, TSP and such), but I've not been able to find anything about it, and I am not sure what it would be called.

So can I get a nudge or some info on how this should or could be done?