0

I want to join more than a table with different columns, there are tables with more columns than others. I already tested the union but I had to add "Null" to each column that a table doesn't have, any idea how to do it without have to do one by one?

Query:

select Proc_Date, Proc_Id, Proc_Robot, null as Info_Qt_Agile, null as Info_Qt_UploadRecibo 
from temp.Teste_CLF2019U007
Union 
select Proc_Date, Proc_Id, Proc_Robot, null as Info_Qt_Agile, Info_Qt_UploadRecibo 
from temp.Teste_CO2019U003
union all
select Proc_Date, Proc_Id, Proc_Robot,Info_Qt_Agile, null as Info_Qt_UploadRecibo 
from temp.Teste_CO2019U016
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I don't see anything wrong with how you're doing it above, where you have placeholders for columns that don't exist. As long as you don't have hundreds of columns to align, this should pretty quick to edit and verify. Just check if you want union or union all. – Isolated Oct 19 '20 at 16:51
  • Are the combination of Proc_Date, Proc_Id, Proc_Robot a unique row key? Are each of those 3 columns NOT NULL? – SteveC Oct 19 '20 at 17:04
  • You can use outer join which will resolve your issue of explicitly adding null. This is not something new issue which occurs to you. Please search your question on the community to find existing answers before posting a new question. Refer https://stackoverflow.com/questions/4796872/how-to-do-a-full-outer-join-in-mysql/4796911 – Patrick Oct 19 '20 at 18:19

0 Answers0