Use result of one SQL query as attribute to another query. (MYSQL)

0

I have the following structure:

tabela (Grupo):
-cd_grupo
-nm_grupo
-ds_filtros -> Aqui armazeno parte do comando SQL utilizado como filtro , para posteriormente atualizar.

I have stored the following information.

cd_grupo  |   nm_ grupo  |   ds_filtro
   1      |    grupo1    | AND (uf = 'PR') AND (genero = 'F')
   2      |    grupo2    | AND (nasc >= '1990-02-20')

There is another link table where employees are linked according to the group filter.

cd_grupo  |   cd_funcionario
   1      |        14
   1      |        19
   1      |        35

My question is to update the binding table when the employee's status changes and when a new employee is added.

In this way I know that it does not work, but the idea is this:

SELECT cd_funcionario FROM funcionario WHERE (SELECT ds_filtros FROM grupo)

That would bring the filters "AND (uf = 'PR') AND (gender = 'F')" and add after the WHERE clause

Is there any alternative to storing the filters, or if you have to search all the filters in the group table and apply them to another SQL command, be it REPLACE, UPDATE or INSERT?

I'm using PHP with Mysql.

    
asked by anonymous 30.09.2018 / 22:13

1 answer

0

I have an example that I have done a few days, so yours will look more or less like this in my bank have Thenheshows

<?php$host="localhost";
    $usu="root";
    $senha="";
    $bd="ts";
    $link = mysqli_connect($host, $usu, $senha, $bd);
        $sql="SELECT 'numero' FROM 'ts' WHERE id=1";
        $execut=mysqli_query($link,$sql);
        while($row= MYSQLI_FETCH_ARRAY($execut)){
                $filtro=$row['numero'];
        }
        $sql="SELECT 'numero' FROM 'ts' WHERE $filtro";
        $execut=mysqli_query($link,$sql);
        while($row= MYSQLI_FETCH_ARRAY($execut)){
                $filtro=$row['numero'];
        }
        echo $filtro;
    ?>
    
01.10.2018 / 16:06