Nick Birke
Nick Birke

Reputation: 137

Self-referencing table - how to get results as one table

I have a table like this

enter image description here

Please forgive the column names they are driven by internal standards. What I would like to know is how to query this self-referencing table so the output is something like this:

| PARENT REASON |    CHILD REASON  |
| ---------------------------------|
| Electrical    | Wire Broke       |
| Electrical    | Fuse Blown       |
| Mechanical    | Bad Gear         |
| Mechanical    | Bolt Broke       |

You help is greatly appreciated.

Upvotes: 0

Views: 85

Answers (2)

ngneema
ngneema

Reputation: 444

SELECT T2.strReason as [PARENT REASON], T1.strReason as [CHILD REASON]
FROM IngTable as T1
JOIN IngTable as T2
  ON T1.IngReasonParent = T2.IngReason

Upvotes: 1

Elias
Elias

Reputation: 2632

I believe you should break that apart into a category table, but...

SELECT SELECT a.strReason as [PARENT REASON], b.strReason as [CHILD REASON]
FROM table1 AS a 
INNER JOIN table1 as b ON b.lngReasonParent = a.lngReason 

Upvotes: 0

Related Questions