Como combinar consultas por união em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server
This T-SQL code uses the UNION clause to combine the results of two different queries, one for the table [f].[ Mercado_Exportacao] and another for table [f]. [Mercado_Importacao]. I'll explain each part of the code
Union Part One:
CO_MES], [KG_LIQUIDO], 'Export' AS TYPE FROM [f]. [Mercado_Exportacao]
UNION Operator
Union Part Two:
CO_MES], [KG_LIQUIDO], 'Import' AS TYPE FROM [f]. [Mercado_Importacao]
The final result of the query is the combination of the results of the two parts, where each row will have the columns "CO_ANO", "CO_MES", "KG_LIQUIDO" and "TYPE". The "TYPE" column indicates whether the data is export-related or import-related. This is useful when you need to group or analyze data from different related tables.
Data Scientist and Consultant for Digital and Analytics Solutions
@fabioms