且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sql查询自引用表查询

更新时间:2023-02-02 22:28:26

此查询将为您提供所有具有父项的类别以及父母的名字.
This query will get you all Categories that have a parent along with the name of the parent.
SELECT  C.Category AS 'Category', 
        C2.Category As 'Parent'
  FROM  Category C
           INNER JOIN Category C2 ON C2.CategoryId = C.ParentCategoryId
 WHERE  C.ParentCategoryId > 0