how to get biggest result from a sql result in postgresql
===

I am using postgresql 8.3 and I have a simple sql query:
   
    select a.id,a.bpm_process_instance_id,a.actor_id 
    from bpm_task_instance a where a.bpm_process_instance_id in 
	(
	   select bpm_process_instance_id 
           from incident_info 
           where status = 12 and registrant = 23
	)


so, I got a result set like this:

    

    id    instance_id  actor_id
    150     53            24
    147     53            26
    148     53            25
    161     57            26
    160     57            26
    158     57            24
    165     58            23
    166     58            24
    167     58            24

now, I want to get the max id by instance_id, and the result is like blew
    
    id    instance_id  actor_id
    150     53            24
    161     57            26
    165     58            23

how could I get the result ? I use the following sql, but get an error.

ERROR:  relation "x" does not exist

    select * from (
       select a.id,a.bpm_process_instance_id,a.actor_id 
       from bpm_task_instance a where a.bpm_process_instance_id in 
	(
	   select bpm_process_instance_id 
           from incident_info where status = 12 and registrant = 23
	) 
     ) as x
     where x.id = 
     (
	   select max(id) from x 
           where bpm_process_instance_id = x.bpm_process_instance_id
      )

   anyone who can help me , thanks a lot!
