Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:27:44+00:00 2026-06-08T18:27:44+00:00

I am using postgresql 8.3 and I have a simple sql query: SELECT a.id,a.bpm_process_instance_id,a.actor_id

  • 0

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
167     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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:27:46+00:00Added an answer on June 8, 2026 at 6:27 pm
    DROP SCHEMA tmp CASCADE;
    CREATE SCHEMA tmp ;
    SET search_path=tmp;
    
    CREATE TABLE the_table
            ( id INTEGER NOT NULL
            , instance_id INTEGER NOT NULL
            , actor_id INTEGER NOT NULL
            );
    INSERT INTO the_table(id, instance_id, actor_id) VALUES
    (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)
            ;
    
    SELECT id, instance_id, actor_id
    FROM the_table dt
    WHERE NOT EXISTS (
            SELECT *
            FROM the_table nx
            WHERE nx.instance_id = dt.instance_id
            AND nx.id > dt.id
            );
    

    Result (note: the last row differs!):

    DROP SCHEMA
    CREATE SCHEMA
    SET
    CREATE TABLE
    INSERT 0 9
     id  | instance_id | actor_id 
    -----+-------------+----------
     150 |          53 |       24
     161 |          57 |       26
     167 |          58 |       24
    (3 rows)
    

    UPDATE: this is the query including the other subquery and the missing table, and the original (ugly) column names, all packed into a CTE:

    WITH zcte AS (
            SELECT ti.id AS id
                    , ti.bpm_process_instance_id AS instance_id
                    , ti.actor_id AS actor_id
            FROM bpm_task_instance ti
            WHERE EXISTS ( SELECT * FROM incident_info ii
                    WHERE ii.bpm_process_instance_id = ti.bpm_process_instance_id
                    AND ii.status = 12
                    AND ii.registrant = 23
                    )
            )
    SELECT id, instance_id, actor_id
    FROM zcte dt
    WHERE NOT EXISTS (
            SELECT *
            FROM zcte nx
            WHERE nx.instance_id = dt.instance_id
            AND nx.id > dt.id
            );
    

    UPDATE addendum:

    Oops, the bad news is that 8.3 did not have CTE’s yet. (think about upgrading). The good news is: as a workaround you could make zcte () as a (temporary) VIEW, and refer to that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql function that does a simple sql select statement: CREATE OR
I am using Postgresql 8.3 and have the following simple function that will return
I have written a simple forum in PHP using PostgreSQL. The forum consists of
I have a simple app running on tomcat (using Postgresql). I deployed it to
(I am using PostgreSQL) I have a table which stores transactions to an account.
Using PostgreSQL triggers, is it possible to record the changes that have happened to
I have developed an application using postgresql and it works well. Now I need
I'm using PostgreSQL 9.1 and I have this data structure: A B ------- 1
I have a postgresql database and am using it for a project which handles
In pom.xml I have (taken from http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/ ): <properties> <openjpa.sql.action>refresh</openjpa.sql.action> <database.driver.name>org.postgresql.Driver</database.driver.name> <database.connection.url>jdbc:postgresql://myURL</database.connection.url> <database.user>user</database.user> <database.password>password</database.password>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.