Reputation: 137
I have a table like this
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
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
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