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

  • SEARCH
  • Home
  • 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 8914859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:49:59+00:00 2026-06-15T04:49:59+00:00

I am facing a pecular problem in writing a sql query for below functionality:

  • 0

I am facing a pecular problem in writing a sql query for below functionality:
Consider below table:

---------------------------------
 AccountNumber     JobNumber
---------------------------------
    1234            1111113
    1234            1111112
    1234            1111111
    1212            1111131
    1212            1111132

I want to fetch a latest job number for account number passed to a query. For eg: If I pass 1234 as a account number, I need to get 1111113 and if I pass 1212 I should get 1111131. How to write a PL/SQL query to achieve this? We will pass multiple account number like AccountNumber IN ('1234','1212'). So for each account number I need to get latest job number.

Currently I have tried without using IN like this:

SELECT * 
  FROM (SELECT JobNumber 
          FROM TABLE1 
          WHERE AccountNumber = ?) 
 WHERE ROWNUM = 1

and in Java JDBC I am looping thorugh account number ArrayList and executing JDBC against Oracle db. But as you know it is not a feasible solution, if there are 4000 accounts performance hits.

Can you help in writing this SQL Query?

EDIT: Here latest means highest jobnumber, for eg: out of 1111113 and 1111112. 1111113 is the latest data

  • 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-15T04:50:01+00:00Added an answer on June 15, 2026 at 4:50 am

    There are several ways:

    SQL> create table t1(AccountNumber, JobNumber) as
      2  (
      3  select 1234,  1111113 from dual union all
      4  select 1234,  1111112 from dual union all
      5  select 1234,  1111111 from dual union all
      6  select 1212,  1111131 from dual union all
      7  select 1212,  1111132 from dual
      8  )
      9  ;
    
    Table created
    
    
    
    
    SQL> select t.AccountNumber
      2       , max(t.JobNumber) as JobNumber
      3    from t1 t
      4   where AccountNumber in (1212, 1234)  -- for example
      5   group by AccountNumber
      6  ;
    
    ACCOUNTNUMBER  JOBNUMBER
    ------------- ----------
             1234    1111113
             1212    1111132
    

    OR

    SQL> select AccountNumber
      2       , JobNumber
      3    from ( select t.AccountNumber
      4                , t.JobNumber
      5                , row_number() over(partition by t.AccountNumber order by t.JobNumber desc) rn
      6             from t1 t
      7            where AccountNumber in (1212, 1234) -- for example
      8         ) t
      9  where t.rn = 1
      10  ;
    
    ACCOUNTNUMBER  JOBNUMBER
    ------------- ----------
             1212    1111132
             1234    1111113
    

    OR

    SQL> select AccountNumber
      2       , JobNumber
      3    from ( select t.AccountNumber
      4                , t.JobNumber
      5                , max(JobNumber) over(partition by t.AccountNumber) mjn
      6             from t1 t
      7            where AccountNumber in (1212, 1234)   -- for example
      8         ) t
      9  where t.JobNumber = t.mjn
      10  ;
    
    ACCOUNTNUMBER  JOBNUMBER
    ------------- ----------
             1212    1111132
             1234    1111113
    
    SQL> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Facing problem for generating SQL Server Query In the Following query dynamic conditions are
I facing some problem in SQL query.I try to use select result in other
Facing a problem, it seems my data stored in SQL Server does not stored
Facing problem with every fetch i want to make using EF Query model.Place here
I am facing problem with an Oracle Query in a .net 2.0 based windows
I am facing a peculiar problem. The problem is, my webapp is being installed
Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
Im facing one problem in streaming data capture for reading the broadcast data during
When facing the problem of validating a property in a JSF2 application there are

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.