Ga zelf terug naar de tafel om de werkelijke ouder van het kind te vinden.
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)
Dit zou beide onderliggende items van de categorie "Computers" opleveren. Is dat wat u zoekt?
Je kunt dit natuurlijk omdraaien om alle kinderen van een specifieke ouder of van alle ouders weer te geven:
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
Of, als u alleen de kinderen van categorie "Computers" wilt, verander dan uw ParentCategoryId in 10
SELECT CategoryID, ParentCategoryID, Name, Published, Deleted, PictureID
FROM Nop_Category
WHERE (Deleted = 0)
AND (Published = 1)
AND (ParentCategoryID = 10)