title: Include values from other rows in output Postgressql
body: <p>I have a table with Infos about Objects for Rent. (Postgres v.10)</p>
  <p><a href="https://dbfiddle.uk/?rdbms=postgres_10&amp;fiddle=25aefcbf9a1cb3baa704fd9a5a0bb7ff" rel="nofollow noreferrer">Example</a></p>
  <pre><code>id  start_date  end_date    objekt_id   person_id
  1   2011-10-01  2015-10-31  5156        18268
  2   2015-11-01  2018-04-30  5156        18268
  3   2018-05-01  2021-03-31  5156        18269
  4   2021-04-01  2021-05-15  5156    
  5   2021-05-16  2100-01-01  5156        18270
  6   2021-03-14  2100-01-01  5160        18270
  </code></pre>
  <p>Now i want to add the last id and the next id on the same row where the objekt_id and person_id is not null.</p>
  <p>Wished output for Object 5156</p>
  <pre><code>    id  start_date  end_date    objekt_id   person_id   last_id   next_id
      1   2011-10-01  2015-10-31  5156        18268                 2
      2   2015-11-01  2018-04-30  5156        18268       1         3
      3   2018-05-01  2021-03-31  5156        18269       2         5 --here next is 5 since 4 has person_id null
      4   2021-04-01  2021-05-15  5156                            
      5   2021-05-16  2100-01-01  5156        18270       3         
      6   2021-03-14  2100-01-01  5160        18270
  </code></pre>
  <p>The goal in the end for me is to find out who rents something at a specific date and who rented it the last time and who is the next one to rent (if there is one).</p>
  <p>I tried something like this but it doensn't work.</p>
  <pre><code>select r.id,r.start_date,r.end_date,r.objekt_id,r.person_id, rentlast.id
  from rent r
  inner join rent rentlast on rentlast.id = (select r3.id from rent r3 where r3.objekt_id = r.id and r3.person_id is not null and r3.id&lt;r.id order by id desc limit 1 )
  </code></pre>
  <p>What is the best solution for this?</p>