Tom Lane a écrit : <blockquote type="CITE">Richard NAGY <richard@presenceweb.com> writes: <br />> SELECT
aes.ent_id,e.type, e.nom, aes.sect_id as voulu, <br />> cvd_new(current_date, e.date_entree, 'new') FROM
ass_entrep_sectactaes, <br />> entreprise e WHERE e.id = aes.ent_id and aes.sect_id <> 3 and <br />>
aes.sect_id<> 9 <br />> and aes.sect_id <> 1 and aes.sect_id <> 13 and aes.sect_id = 56 <br />>
UNION<br />> SELECT distinct on (aes.ent_id) aes.ent_id, e.type, e.nom, aes.sect_id, <br />>
cvd_new(current_date,e.date_entree, 'new') FROM ass_entrep_sectact aes, <br />> entreprise e WHERE e.id = aes.ent_id
andaes.sect_id <> 3 and <br />> aes.sect_id <> 9 <br />> and aes.sect_id <> 1 and aes.sect_id
<>13 and aes.sect_id <> 56 and <br />> aes.ent_id <br />> not in (SELECT ent_id FROM
ass_entrep_sectactWHERE sect_id = 56 and <br />> sect_id <> 3 <br />> and sect_id <> 9 and sect_id
<>1 and sect_id <> 13) ORDER BY e.type, <br />> e.nom <p>ORDER BY applied to the result of a UNION has
tobe on the output <br />columns of the UNION. "e.type" etc are names of input-table columns. <br />Try just "type"
and"nom", which will refer to the second and third <br />output columns of the UNION. <p>Pre-7.1 got this wrong (and
wouldsometimes produce wrong output <br />ordering or even a backend crash, if the arms of the UNION didn't <br />all
yieldthe same datatype). <p> regards, tom lane</blockquote> Hello Tom, <p>Yes, thanks a lot. It
works!<br />Regards. <pre>--
Richard NAGY
Presenceweb</pre>