title: Linked list concept in postgresql
body: <p>I am new to postgresql, can you please guide me about my query listed below?</p>
  <p>I have a table in postgres (database) named &quot;<strong>app</strong>&quot; having two columns &quot;<strong>aid</strong>&quot; and &quot;<strong>cid</strong>&quot;.</p>
  <p>Table Name: <strong>app</strong></p>
  <p><strong>aid</strong>   |  <strong>cid</strong></p>
  <p>a1 | a3</p>
  <p>a2 | null</p>
  <p>a3 | a5</p>
  <p>a4 | a6</p>
  <p>a5 | null</p>
  <p>a6 | null</p>
  <p>What I want to display(using sql query in server), when I select <strong>&quot;a1&quot;</strong> or <strong>&quot;a3&quot;</strong> or <strong>&quot;a5&quot;</strong> from <strong>aid</strong> using sql query, I want to list all values associated with <strong>&quot;a1&quot;</strong> and its child <strong>cid</strong> (in this case I want an output =  <strong>a1 a3 a5</strong>), its like a linked list <strong>a1</strong> is connected to <strong>a3</strong> and <strong>a3</strong> is connected to <strong>a5</strong>.</p>
  <p>If I select <strong>&quot;a4&quot;</strong> using sql query, I need an output like this(<strong>&quot;a4 a6&quot;</strong>)</p>