MySQL query - [id's] separated by comma

0

I have two tables: table A has certain fields, including its primary key Id ; in the development they have table B with a field with which table A is related (conceptually, since there is no relationship created in the database).

In certain records of B, the field id_Item_A has different ids separated by commas (the development is like this and I can not change it). I would like to know if there is a way to do a INNER JOIN that would bring me the fields of the A's Id that are in B.

Tabla A:
******************
**|id|***|Item |**
******************
**|1 |***|item1|**
**|2 |***|item2|**
**|3 |***|item3|**

Tabla B:
********************************
**|id***|id_Item_A|***|elemento|
********************************
**|1 |***|  1,2   |***|elemento1|
**|2 |***|  2,3   |***|elemento2|
**|3 |***|  1,3   |***|elemento3|

This is the example for the tables that I have. So, I would like to know if it is possible to do a INNER JOIN and that, for example, in elemento2 tell me that it is related to Item2 e Item3 .

Thank you.

    
asked by Andress Blend 22.02.2017 в 14:53
source

1 answer

0

With the function 'FIND_IN_SET (search string, string list) you could get it, it would be something like that

select * from TABLAA tblA inner join TABLAB tblB on 0 != FIND_IN_SET(tblA.id, tblB.id_Item_A)

What this function does is look for a string in a string list, returning the position it is in the list and returning 0 if it can not be found.

    
answered by 22.02.2017 в 15:34