Doubt to use Replace along with Inner Join

2

I'm using Inner Join to combine two tables:

SELECT eventos.colab_id, colaboradores.setor 
FROM colaboradores INNER JOIN eventos
ON colaboradores.id = eventos.colab_id

So far so good, however I have cases where I need to delete the " character of eventos.colab_id . REPLACE does this, however I'm not aware use the syntax along with Inner Join .

    
asked by anonymous 31.10.2018 / 17:53

2 answers

2

Nothing changes the JOIN in the question, you can apply replace normally:

SELECT REPLACE( eventos.colab_id, '"', '') AS colabid, colaboradores.setor 
FROM colaboradores INNER JOIN eventos
ON colaboradores.id = eventos.colab_id

If it's in the comparison:

SELECT eventos.colab_id, colaboradores.setor 
FROM colaboradores INNER JOIN eventos
ON colaboradores.id = REPLACE( eventos.colab_id, '"', '');

Now, if this second case is much better fix the bank and leave the field as numeric. To permanently remove quotes:

UPDATE eventos SET colab_id = REPLACE( colab_id, '"', '');

and after that convert the column to integer, to avoid problems.

    
31.10.2018 / 18:10
1

The REPLACE function of MySql has the following syntax: / p>

  

REPLACE (str, find_string, replace_with)

Parameters:

  • The string
  • The string you want to replace
  • The string that will replace the searched instance of item 2
  • In your case, it would look like this:

        SELECT eventos.colab_id, REPLACE(eventos.colab_id,'"',''),  colaboradores.setor 
        FROM colaboradores INNER JOIN eventos
        ON colaboradores.id = eventos.colab_id
    

    If it is in the second table, it looks like this:

       SELECT eventos.colab_id,  colaboradores.setor 
       FROM colaboradores INNER JOIN eventos
       ON colaboradores.id = REPLACE(eventos.colab_id,'"','')
    

    Reference: link

        
    31.10.2018 / 18:11