title: Postgresql recursive self join
body: <p>My table in postgres looks like below, Table stores a chain sort of relation between IDs and I want to have a query which can produce the result like "vc1" -> "rc7" or "vc3"->"rc7", I will only query on the IDs in first column ID1 </p>
  
  <pre><code>ID1     ID2
  "vc1"   "vc2"
  "vc2"   "vc3"
  "vc3"   "vc4"
  "vc4"   "rc7"
  </code></pre>
  
  <p>So I want to supply some "head" id here for which I have to fetch the tail(last in the chain) id.</p>