Read phpMyAdmin column with multiple records

2

I have a table in phpMyAdmin with a field that stores several values, the column is named as subfilter id, I need to read each value of that, since they are id's that are related to another table, the field is a varchar. p>

The table is this, the field I need to read is what is marked, see:

I could not find anything related to the searches I did.

    
asked by anonymous 29.01.2015 / 01:16

2 answers

3

If the goal is to make a JOIN with another table, MySQL provides a shortcut that is the FIND_IN_SET . But it has performance problems, the correct thing would be to model the bank in another way and use a relationship table, as already suggested in Alfredo Silveira's answer and in rray's comment.

To show, here's an example of gambiarra with FIND_IN_SET :

SELECT tabela1.*
FROM tabela1
    INNER JOIN tabela2
    ON FIND_IN_SET(tabela2.id, tabela1.id_subfiltro) > 0
    
29.01.2015 / 01:46
3

I recommend that you do a better modeling of the database, creating a relational table for that case.

For example, a table between equipment and workers both have an identifier ID , to relate appropriately with a cardinality N to N it would be nice to create a equipamentos_trabalhadores table where there would be id_equipamento and id_trabalhor , this could relate N records, and can be queried only by id_equipamento or id_trabalhor thus making access easier and faster.

But if you want to continue with this modeling, you can bring all the data to the programming, or to the query, and use regular expression methods that vary depending on the programming language you want.

In order to use PhpMyAdmin, I imagine that I should use PHP, so I will put a regular expression reference in PHP, but if it is not this function is available in all languages, it follows reference:

link

With this method you can get particles of a certain text, so you can separate the ids you want, but this is not very suitable for this treatment.

    
29.01.2015 / 01:25