How to make several queries with the same fields but different data in the tables?

2

I would like to join two tables with the same fields but they have leaders loaded in their tables. example

select folio,'ALUMNO' AS ent_sal, observaciones 
from ALUMNO 
where activo='0'

Y

select folio,'MATERIA' as ent_sal, observaciones 
from MATERIA 
where activo='0'

Want it to appear on a single table If someone please.

    
asked by AraceLi Torres 08.08.2016 в 16:05
source

1 answer

2

Does it give me the impression that you want to have a single result? In that case, you only need to use UNION ALL :

SELECT folio,
       'ALUMNO' ent_sal,
       observaciones
FROM ALUMNO
WHERE activo = '0'
UNION ALL
SELECT folio,
       'MATERIA' ent_sal,
       observaciones
FROM MATERIA
WHERE activo = '0';

Now, if you want to save that result in a new table you can use INTO :

SELECT folio,
       'ALUMNO' ent_sal,
       observaciones
INTO dbo.NuevaTabla
FROM ALUMNO
WHERE activo = '0'
UNION ALL
SELECT folio,
       'MATERIA' ent_sal,
       observaciones
FROM MATERIA
WHERE activo = '0';
    
answered by 08.08.2016 / 16:09
source