I have this query:
SELECT * FROM (
SELECT distinct
db_name() as 'Banco_de_Dados',g.KM_SIMBOL, fotos = COUNT(*) OVER (PARTITION BY d.globalid ORDER BY d.globalid),d.GDB_FROM_DATE as Data , g.RODOVIA , g.CODIGO
FROM [dbo].GO_35_BR070_PE_VERTICAL_MANUTENCAO d
INNER JOIN [dbo].GO_35_BR070_PE_VERTICAL_MANUTENCAO__ATTACH a
ON a.REL_GLOBALID = d.GlobalID
INNER JOIN GO_35_BR070_PE_VERTICAL g
ON D.vertical_rel_globalid= G.VERTICAL_GLOBALID
) d
WHERE fotos > 2
order by d.Data
UNION --USEI UNION PARA JUNTAR O RESULTADO DE UM MESMO BANCO DE DADOS
SELECT * FROM (
SELECT distinct
db_name() as 'Banco_de_Dados',g.KM_SIMBOL, fotos = COUNT(*) OVER (PARTITION BY d.globalid ORDER BY d.globalid),d.GDB_FROM_DATE as Data , g.RODOVIA , g.CODIGO
FROM [dbo].GO_35_BR070_TREVOGIRASSOL_PE_VERTICAL_MANUTENCAO d
INNER JOIN [dbo].GO_35_BR070_TREVOGIRASSOL_PE_VERTICAL_MANUTENCAO__ATTACH a
ON a.REL_GLOBALID = d.GlobalID
INNER JOIN GO_35_BR070_PE_VERTICAL g
ON D.vertical_rel_globalid= G.VERTICAL_GLOBALID
) d
WHERE fotos > 2
order by d.Data
WHEN I USE THAT WAY THE "UNION" IS SUBLIMATED IN RED SIGNING THAT THERE IS ERROR. But if I take UNION to my query it works without problem. Anyone to help me?