Detail with SQL - UNION & ORDER BY

0

I have the following query

SELECT matricula_veh as 'Identificacion', 
       concat(marca_veh,' ',modelo_veh) as 'InfoName',
       'Vehiculo' KindData 
  FROM vehiculos 
 UNION 
SELECT id_per as 'Identificacion', 
       concat(nom_per,' ',ape_per) as 'InfoName',
       'Usuario' KindData 
  FROM personas 
 UNION 
SELECT id_per_ad as 'Identificacion',
       matricula_veh_ad as 'InfoName',
       'AdminVehiculo' KindData 
  FROM admin_vehiculos 
 UNION 
SELECT id_reg as 'Identificacion',
       nomc_pas_reg as 'InfoName',
       'RegistroViaje' KindData 
  FROM registro_viaje

It works perfect, but I would like you to be able to organize all the results chronologically, in each table there is a column in which a TIMESTAMP is printed. How can I make the query then?

The organization must be global, not table by table.

    
asked by Máxima Alekz 19.10.2016 в 03:10
source

1 answer

1

Improvising I found the solution, the query is now

SELECT matricula_veh as 'Identificacion', 
       concat(marca_veh,' ',modelo_veh) as 'InfoName',
       'Vehiculo' KindData, 
       dato_veh as 'Fecha' 
  FROM vehiculos 
 UNION 
SELECT id_per as 'Identificacion', 
       concat(nom_per,' ',ape_per) as 'InfoName',
       'Usuario' KindData, 
       datoAfiliacion_per as 'Fecha' 
  FROM personas 
 UNION 
SELECT id_per_ad as 'Identificacion',
       matricula_veh_ad as 'InfoName',
       'AdminVehiculo' KindData, 
       dato_ad as 'Fecha' 
  FROM admin_vehiculos 
 UNION 
SELECT id_reg as 'Identificacion',
       nomc_pas_reg as 'InfoName',
       'RegistroViaje' KindData, 
       datoPartida_reg as 'Fecha' 
  FROM registro_viaje 
 ORDER BY Fecha

From each table I took the value from TIMESTAMP to 'Date' as a column, and at the end I added ORDER BY Date , so I got the results sorted by date globally from different tables:))

    
answered by 19.10.2016 / 03:49
source