INSERT taking SELECT from two tables with WHERE - MYSQL

Asked

Viewed 87 times

0

Hello!

Follow my Insert and below I explain what is happening:

INSERT INTO tab_relatorio_ext 
SELECT 
    t1.CODIGO_EXT, 
    t1.TIPO_EXT, 
    t2.NOME_SITUACAO_EXT 
FROM Tab_Coletados_Ext as t1 
JOIN tab_ext_situacao as t2 ON t2.ID_SITUACAO_EXT = t1.SITUACAO_EXT
WHERE t1.TIPO_EXT = 'BC';

I need to enter data in the table TAB_RELATORIO_EXT, which comes from two other tables (T1 e T2). Conditions:

  • field t2.nome_situacao_ext: The ID to bring this information I am passing on after the ON in my select. I believe the error is here.

  • field t1.tipo_ext is equal to 'BC'.

The insert even works, but when it meets the condition after the ON he already gives a insert and then another when you answer the Where. That is, the item is getting duplicated. Does anyone have any suggestions?

Thank you!

  • the select brings only one return line? if it is the case, plays what has in the where as and of on that should solve =p

  • Dude, I removed the database. I created another one from scratch and it worked the way I posted it. Puts...programming has time boiling blood of gnt. Vlww!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.