Gå selv tilbage til bordet for at finde den faktiske forælder til barnet.
SELECT c1.CategoryID, c2.ParentCategoryID, c1.Name, c2.Name as ParentName, c1.Published, c1.Deleted, c1.PictureID
FROM Nop_Category c1
JOIN Nop_Category c2 on c1.ParentCategoryId = c2.CategoryId
WHERE (c1.Deleted = 0)
AND (c1.Published = 1)
AND (c1.ParentCategoryID = 10)
Dette ville returnere begge børn i kategorien "Computere". Er det det, du leder efter?
Selvfølgelig kan du vende dette om for at vise alle børn af en bestemt forælder eller fra alle forældre:
SELECT c.*, p.* -- shortened, but you should pick specific columns
FROM Nop_Category p -- parent
JOIN Nop_Category c ON c.ParentCategoryId = p.CategoryId -- children
WHERE p.ParentCategoryId = 0 -- all top level parents
SELECT c.*, p.* -- shortened, but you should pick specific columns
FROM Nop_Category p -- parent
JOIN Nop_Category c ON c.ParentCategoryId = p.CategoryId -- children
WHERE p.CategoryId = 10 -- only the "Computers" category
Eller, hvis du bare vil have børn i kategorien "Computere", skal du ændre dit ParentCategoryId til 10
SELECT CategoryID, ParentCategoryID, Name, Published, Deleted, PictureID
FROM Nop_Category
WHERE (Deleted = 0)
AND (Published = 1)
AND (ParentCategoryID = 10)