title: Category and subcategory through a single query
body: <p>I have a table with fields <code>id,pid,name</code>.I want to fetch the data in the following format through a single query.</p>
  
  <pre><code>id- parent category name- name
  </code></pre>
  
  <p>Name would be either category or subcategory and parent category name would be none if its parent else will be parent category name.</p>