SQL query between two SQL SERVER tables

3

I have two tables (tb_Product_M and tb_Product_Product) that presents a recursion, where a Product can have several Product children. In the table tb_Product_Product contains the data of the parent_Product_id that Products children has this. I need to make a query that shows me the product_id, det_product according to the father_product_id.

 ---------------                        
|tb_Producto   |                        
----------------                          
|id_Producto   |                         
|det_Producto  |                         
---------------    


----------------------
|tb_Producto_Producto|
|id_Producto_Padre   | 
|id_Producto_hijo    | 
---------------------   
    
asked by magi0 31.08.2018 в 21:16
source

2 answers

2

What you need is to make a JOIN with your tables that would be something like this:

SELECT * 
FROM tb_Producto_Producto
INNER JOIN tb_Producto ON tb_Producto.id_Producto = tb_Producto_Producto.id_Producto_Padre
    
answered by 31.08.2018 в 21:22
2

something like that? According to the little information you give, I understood that you want to do this:

select * from tb_Producto   
where id_Producto   in (
select id_Producto_hijo  from tb_Producto_Producto 
where  id_Producto_Padre   = id_queBuscas_padre
)
    
answered by 31.08.2018 в 21:23