I have items with categories and those categories can also have categories how can I find the first parent. For example...
CategoriesTbl
CategoryId | CategoryName | parent
-------------------------------------
1 | Category1 | 0
2 | Category2 | 1
3 | Category3 | 2
ItemsTbl
ItemId | CategoryId
-------------------------------------
1 | 3
How could I do a select on the item and join it to the category table with the parent category (CategoryId = 1). The parent category could be nested infinitely deep.