title: get single occurrence of 'parent id' in self join
body: <p>I have table with following set of data :</p>
  
  <pre><code>CategoryId  CategoryName    ParentCategoryId
  1             abc                       null
  2             abc1                      1
  3             abc2                      1
  4             def                       null
  5             def1                      4
  6             def2                      4
  7             ghi                       null
  8             ghi1                      7
  9             ghi2                      7
  </code></pre>
  
  <p>I used self join on this table with the following query :</p>
  
  <pre><code>select p.CategoryId as ParentCategoryId, p.CategoryName as ParentCategoryName,
         c.CategoryId as CategoryId, c.CategoryName as CategoryName 
  from Categories c, Categories p
  where c.ParentCategoryId = p.CategoryId
  </code></pre>
  
  <p>This query produces duplicate rows of parent category id and name for every categoryid.</p>
  
  <p>I want that PraentCategoryId to appear one time for all its respective subcategories.</p>
  
  <p>What I need to do further or is there a way to modify this query.</p>
  
  <p>the result of above query is like</p>
  
  <pre><code>ParentCategoryId    ParentCategoryName  CategoryId  CategoryName
      1             abc                       2        abc1
      1             abc                       3        abc2
      4             def                       5        def1
      4             def                       6        def2
      7             ghi                       8        ghi1
      7             ghi                       9        ghi2
  </code></pre>