title: How to correct my SQL statement?
body: <p>I have this SQL statement :</p>
  
  <pre><code>SELECT pgdd1.DT_DEPOT AS DT_LAST,pgdd.DT_DEPOT AS DT, pgdd.ETAT AS ETAT, pgtd.NOM_DOCUMENT AS NOM_DOCUMENT  
  FROM pg_detachements_documents pgdd
  LEFT JOIN pg_types_documents pgtd ON pgtd.ID=pgdd.ID_DOCUMENT
  LEFT JOIN pg_detachements_documents pgdd1 on pgdd1.ID = pgdd.ID
  WHERE pgdd.ID_DETACHEMENT = 4 
  ORDER BY pgdd.ID  
  DESC 
  LIMIT 5
  </code></pre>
  
  <p>This one works fine, but when I try to show only the first row of DT_LAST i get an SQL Syntax error</p>
  
  <p>I m trying this :</p>
  
  <pre><code>SELECT FIRST(pgdd1.DT_DEPOT) AS DT_LAST,pgdd.DT_DEPOT as DT, pgdd.ETAT AS ETAT, pgtd.NOM_DOCUMENT AS NOM_DOCUMENT  
  FROM pg_detachements_documents pgdd
  LEFT JOIN pg_types_documents pgtd ON pgtd.ID=pgdd.ID_DOCUMENT
  LEFT JOIN pg_detachements_documents pgdd1 on pgdd1.ID = pgdd.ID
  WHERE pgdd.ID_DETACHEMENT = 4 and pgdd1.DT_DEPOT = pgdd.DT_DEPOT
  ORDER BY pgdd.ID  
  DESC 
  LIMIT 5
  </code></pre>
  
  <p>I tried to use a where <code>pgdd1.DT_DEPOT in (same first select but with limit 1)</code> but my SQL server says that he dont support limit in inner select.</p>
  
  <p>Here is my result of first query :
  <a href="https://i.stack.imgur.com/gJuku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJuku.png" alt="My first query result"></a></p>
  
  <p>I want only first (DT_LAST value) in all rows.</p>
  
  <p>My ultimate goal is to select the first group of rows of a group by elements in this case are the first 2 rows where DT is the same.</p>