title: How can i compare two dates in the same column and get the oldest?
body: <p>I am new with SQL and i recived a good task.<br>
  The task is:<br>
  I have two tables, one called TICKETS end other called LOGS.  </p>
  
  <p>Tickets:<br>
  ID | Ticket | Open_Date<br>
  10 | 40000 | 2015-03-01 11:00:00<br>
  11 | 40001 | 2015-03-01 12:00:00<br>
  12 | 40002 | 2015-03-01 13:00:00<br>
  13 | 40003 | 2015-03-01 14:00:00<br>
  14 | 40004 | 2015-03-01 15:00:00  </p>
  
  <p>Logs:<br>
  ID | Ticket_id | Time_Stamp | Description<br>
  01 | 10 | 2015-03-01 11:10:00| In Progress<br>
  02 | 10 | 2015-03-01 11:15:00| In Progress<br>
  03 | 10 | 2015-03-01 11:20:00| Transfered<br>
  04 | 11 | 2015-03-01 12:10:00| In Progress<br>
  05 | 11 | 2015-03-01 12:15:00| Transfered<br>
  06 | 11 | 2015-03-01 12:20:00| In Progress<br>
  07 | 12 | 2015-03-01 13:05:00| Transfered<br>
  08 | 12 | 2015-03-01 13:10:00| In Progress<br>
  09 | 12 | 2015-03-01 13:15:00| In Progress<br>
  10 | 13 | 2015-03-01 14:05:00| Transfered<br>
  11 | 13 | 2015-03-01 14:10:00| Transfered<br>
  12 | 13 | 2015-03-01 14:15:00| In Progress<br>
  13 | 14 | 2015-03-01 15:10:00| Transfered<br>
  14 | 14 | 2015-03-01 15:15:00| In Progress<br>
  15 | 14 | 2015-03-01 15:20:00| Transfered  </p>
  
  <p>As showed in the tables, i have many logs to a single ticket. What i need to do is find the first log with description "In Progress" and get its date(the oldest). If it comes after a log of "Transfered" get the date of the log "Transfered" as "Open_Date" of the ticket and then get the date of the first log "In Progress". </p>
  
  <p>The query that was give to me brings just the first "In Progress" log:</p>
  
  <pre><code>`Select 
  Tickets.ticket, 
  Tickets.Open_Date,
  Logs.Description,
  Logs.Time_Stamp
  From
  Tickets LEFT JOIN Logs ON Tickets.ID = Logs.Ticket_id
  WHERE
  Logs.Time_Stamp = (Select MIN(Logs_2.Time_Stamp)
                     From Logs AS Logs_2
                     Where Logs_2.Description = 'In Progress')
  And Logs.Time_Stamp &lt; '2015-03-01 14:30:00'
  And Logs.Time_Stamp &gt; '2015-03-01 10:00:00'
  Group By
  Tickets.ticket, 
  Tickets.Open_Date,
  Logs.Description,
  Logs.Time_Stamp`
  </code></pre>
  
  <p>I hope I have been clear on my problem :)<br>
  Could someone help me?<br>
  Thx.</p>