1
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 it this way the "Union" is sublimated in red signaling error. But if you take out UNION my query works fine.Someone to help me out?
because you need to order before the Union?
– rLinhares
Take off the d. date of order by. Use:
order by data
– Wesley Ferreira
@rLines to filter the first query and then join the second query using Union
– Gladiador
@Wesleyferreira even if I take it will not change anything dear friend :(
– Gladiador