Generate Ordered Records of Different Tables

1

I have a problem that has frustrated me for days, I am developing a DB in SQL with the structure of the image, I explain a little:

Each "Completed Part" has several "Parts of Blanquins" and in turn each "Blanquin Part" has several "Stamped Parts", these last two tables are related to other tables as shown in the image, especially with " Dies "and" Operation Condition ", although each one has a different value (one is related to a die and the other to a different one).

The problem is that I want to make a query to show all the "Blanquin Parts" and the "Stamped Parts" both in the same column, I have a query but only shows one or the other

I hope you can help me, Thanks ...

I leave the code of my query:

select ltrim (Rtrim(numero_parte)) as 'Parte Terminada', 
nombre_parte as 'Nombre PT', np.numero as 'Parte Estampada',
np.nombre as 'Nombre', modelo as 'Modelo', proveedor as 'Proveedor',  
cliente as 'Cliente', 
np.centro_trabajo as 'Centro De Trabajo', 
np.imagen as 'Imagen', proceso as 'Proceso', 
nombre_proceso as 'Nombre Del Proceso', colchon as 'Colchon', 
linea as 'Linea', prensa as 'Prensa',
np.linea_contin as 'Linea De Contingencia', almacen as 'Almacen',
FROM partes_terminadas pt inner join numero_parte np on   
np.id_partermi=pt.id 
left join partes_estampadas pe on pe.id_bl=np.id 
left join troquel tro on pe.id_troq=tro.id 
left join linea li on tro.id_linea=li.id 
left join condicion_operacion co on pe.id_co=co.id 
left join material mat on np.id_material=mat.id
    
asked by Cristian 08.03.2018 в 19:05
source

1 answer

1

With the information you provide, you should rewrite that query by substituting this left join:

left join partes_estampadas pe on pe.id_bl=np.id 

For a supposed table "partes_de_blanquit", crossing them by the corresponding field. In turn, you will have to replace in the select fields that came from the previous table with the new table. Then, you can perform a UNION ALL of both queries, keep in mind that they have to return the same number of columns. As an additional help, you can add a new column in each selection that tells you in the final output where each result comes from.

    
answered by 11.03.2018 в 01:14