title: ORACLE/SQL: wm_concat & order by
body: <p>I'm using oracle 11 (not sure about the exact version, but since LISTAGG doesn't work, I suppose it's not release 2) through ODBC and crystal reports 2008.  </p>
  
  <p>Here is the problem I have:  </p>
  
  <p>Here's a table:</p>
  
  <pre><code>TABLE ODB.TASK_CARD_CONTROL  
  ------------------------------------------  
  task_card     control_category     code  
  ------------------------------------------  
  1                  zone             17  
  1                  zone             33  
  1                  zone             21  
  2                  zone             18  
  2                  zone             05  
  3                  zone             55  
  3                  zone             32  
  3                  zone             72 
  </code></pre>
  
  <p>I'm using the WM_CONCAT function to obtain something like this:</p>
  
  <pre><code>task_card      zones
  1              17,33,21
  2              18,05
  3              55,32,72
  </code></pre>
  
  <p>Here is the SQL for that:</p>
  
  <pre><code>SELECT TASK_CARD, WM_CONCAT(code) as ZONES
  FROM ODB.TASK_CARD_CONTROL
  WHERE ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY = 'ZONE'
  GROUP BY TASK_CARD
  </code></pre>
  
  <p>but I'd like the zones to be sorted, so I tried this:</p>
  
  <pre><code>SELECT TASK_CARD, WM_CONCAT(code) as ZONES
  FROM (SELECT TASK_CARD, CODE, CONTROL_CATEGORY FROM ODB.TASK_CARD_CONTROL 
  ORDER BY CODE)
  WHERE ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY = 'ZONE'
  GROUP BY TASK_CARD
  </code></pre>
  
  <p>but for some reason, it returns the following error:</p>
  
  <pre><code>Failed to retrieve data from the database.
  Details: 42S22:[Oracle][ODBC][Ora]ORA-00904: 
  "ODB"."TASK_CARD_CONTROL"."CONTROL_CATEGORY" : invalid identifier
  </code></pre>
  
  <p>I really don't understand what I'm doing wrong here... Can anybody give me a hint ?</p>