title: How to compare the column values of two last inserted specified rows on the same table?
body: <p>I have a data set that is being updated on each operation maden by customers. 
  For example, I am getting a customer's last two operations by</p>
  
  <pre><code>select id, 
         referance 
  from (select id, 
               referance, 
               row_number() 
               over (order by time desc) as seqnum 
        from mytable where id=':id') 
  al where seqnum &lt;= 2
  </code></pre>
  
  <p>where <code>id</code> is getting from a feature file. But now I need to compare the referance values of these two operations.</p>
  
  <p>mytable:</p>
  
  <pre><code>id  | name  | referance  |   time   |
  -------------------------------------
  11  |  abc  |   4589     |   09:05  |
  11  |  abc  |   1234     |   09:04  |
  10  |  xyz  |   0185     |   09:02  |
  15  |  qpr  |   9564     |   08:54  | 
  </code></pre>
  
  <p>so on...</p>
  
  <p>Again, I can get the last two rows with id = 11; and, as far as all columns are not (null), it is returning "true" which is what I want literally.
  But also I'd like to compare if their referances are the same or not; and, when I call the query, it has to return "true" or "false".</p>
  
  <p>Thanks in advance</p>
  
  <p>P.S. I actually just need a useful function or idea. I've already try to use inner join but couldnt manage it:</p>
  
  <pre><code>select table1.id, 
         table1.referance, 
         table2.id, 
         table2.referance 
  from (select id, 
               referance, 
               row_number() 
               over (order by time desc) as seqnum 
        from mytable where id=':id') table1 
        inner join (select id, 
                           referance, 
                           row_number() 
                           over (order by time desc) as seqnum 
                    from mytable where id=':id') table2 
        on table1.referance != table2.referance 
  al where seqnum &lt;= 2 order by seqnum
  </code></pre>