title: Generate Unique ID On a Select in DB2
body: <p>I have a select that look like this:</p>
  
  <pre><code>SELECT * FROM (SELECT DISTICT COL1, COL2, COL3
                 FROM view a WHERE conditions ....
                ) QUERY
  WHERE CONDITIONS... LIMIT 20 OFFSET 0
  </code></pre>
  
  <p>I'm executing this from java and I need this query return an unique id.
  So i try:</p>
  
  <pre><code>SELECT TRIM(CHAR(HEX(GENERATE_UNIQUE()))) AS GUID, QUERY.* FROM (SELECT DISTICT COL1, COL2, COL3
                 FROM view a WHERE conditions ....
                ) QUERY
  WHERE CONDITIONS... LIMIT 20 OFFSET 0
  </code></pre>
  
  <p>This one return an error telling me I can't use this function in that place.
  If i try:</p>
  
  <pre><code>SELECT * FROM (SELECT DISTINCT TRIM(CHAR(HEX(GENERATE_UNIQUE()))) AS GUID, COL1, COL2, COL3
                 FROM view a WHERE conditions ....
                ) QUERY
  WHERE CONDITIONS... LIMIT 20 OFFSET 0
  </code></pre>
  
  <p>I have duplicated rows because it is like I execute query wihout DISTINCT</p>
  
  <p>Does anyone know a way to do it?</p>
  
  <p>I don't know DB2 version (I have tried all solutions from <a href="https://stackoverflow.com/questions/3821795/how-to-check-db2-version">How to check db2 version</a> )</p>