User-719153870 posted
Hi vahid.ch,
If you are talking about SQL Server tables, then the
Joins should be what you are looking fot.
Please check below demo:
create table #Product(ID int, ModelCode varchar(50), ParentId int)
create table #Specs( Id int, Specname varchar(50))
create table #ProductSpec( Id int, productId int, SpecId int, Value varchar(50))
insert into #Product values(1,'SM-F22',null),(2,'SM-F22Black',1),(3,'SM-F22White',1),(4,'SM-A10',null)
insert into #Specs values(1,'Display'),(2,'Memory'),(3,'CPU'),(4,'Color'),(5,'Other')
insert into #ProductSpec values
(1,1,5,'Waterproof'),(2,2,1,'16*10'),
(3,2,2,'64GB'),(4,2,3,'SnapDragonXXX'),
(5,2,4,'Black'),(6,3,2,'128GB'),
(7,3,4,'White'),(8,4,1,'17*12'),
(9,4,2,'128GB'),(10,4,3,'Snapdragon XX'),
(11,4,4,'blue'),(12,4,5,'Waterproof')
select * from #Product
select * from #Specs
select * from #ProductSpec
select ps.productId,p.ModelCode,s.Specname,ps.Value from #ProductSpec ps left join #Specs s on ps.SpecId=s.Id left join #Product p on ps.productId=p.ID where p.ID not in (select ParentId from #Product where ParentId is not null)
Here's the result of this demo:

If there's any misunderstanding, please clarify and provide more detailed information. Thanks!
Best Regard,
Yang Shen