I have two tables that look like this..
Baskets
| id | Array |
|---|---|
| 1 | ["Apple", "Mango", "Pineapple"] |
| 2 | ["Mango", "Pineapple"] |
| 3 | ["Dragonfruit"] |
Stock
| Fruit | Count |
|---|---|
| Apple | 100 |
| Mango | 500 |
| Kiwi | 99 |
| Grapes | 0 |
Through a SQL query, I have to check how many fruits from an array of the first table are present in the second table.
For example, out of ["Apple", "Mango", "Pineapple"] only Apple and Mango is in the Stock table.
Expected outcome:
| id | available |
|---|---|
| 1 | 2 |
| 2 | 1 |
| 3 | 0 |
PS. this is a simplification of the actual problem I'm trying to solve, my main query is how to match a JSON array of objects against some other table. The fruits/stock example is just for explaining the problem.