Trying to replace a value from a column by it's parent in a query

[query result

I want to be able to show the EquipementName, where fk_EquipementParentId = pk_EquipementId.

How would I build my query?

This is what I have so far...

select pk_EquipementId ,fk_EquipementParentId

--, query AS 'Parent Name'

,EquipementName ,EquipementInstallationDate from Firm.dbo.Equipement where fk_EquipementTypeId in (3,15) and bEquipementTemplate = 0

1 answer

  • answered 2018-01-11 20:05 juergen d

    you can do a self-join

    select t1.*, t2.EquipementName as parentName
    from your_table t1
    left join your_table t2 on t1.fk_EquipementParentId = t2.pk_EquipementId