Selection of two fields from different tables, all in one

0

I have two tables in a BD. One is the table of vehiculo and another one of vehiculo_especial .

vehiculo
---------

pk_vehiculo     modelo    matricula    kms_actuales    prox_itv      prox_revision
-----------    -------   ----------    ------------    ---------     -------------
     1            Opel     1111ABC        200000       2018-03-29     400000
     2            Ford     3333ABC        100000       2018-03-12     200000


vehiculo_especial
-----------------


pk_vehiculo     modelo    matricula    horas_trabajo   prox_itv      prox_revision
-----------    -------   ----------    ------------    ---------     -------------
     1         Tractor     2222ABC        20:00:00     2018-03-29     40:00:00

What I'm trying to do is create a query that results in the following:

modelo
------
Opel
Ford
Tractor

I tried this but it does not work out very well. Any help?

select v.modelo, vs.modelo as modelo 
from vehiculo v, vehiculo_especial vs
    
asked by Xerox 27.04.2018 в 16:25
source

1 answer

2

What you are doing in that case is a JOIN , which is not what you want. The JOIN combines the results of the two tables but in the same row.

What you have to do is the union of the two results, for that in SQL you can use UNION :

select modelo from vehiculo
union
select modelo from vehiculo_especial
    
answered by 27.04.2018 / 16:27
source