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 473223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:09:55+00:00 2026-05-13T00:09:55+00:00

Working with Oracle 11g here. I’m trying to figure out how to write a

  • 0

Working with Oracle 11g here.

I’m trying to figure out how to write a specific query against a sample table below:

 ID TYPE   PRIORITY    STATUS   DATE
 ----------------------------------------------------
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 1  Q      A           NEW      01-OCT-2009
 2  R      B           NEW      01-OCT-2009
 2  R      B           NEW      01-OCT-2009
 2  R      B           NEW      01-OCT-2009
 2  R      B           NEW      01-OCT-2009
 3  R      A           NEW      01-OCT-2009
 3  Q      A           NEW      01-OCT-2009
 3  Q      A           NEW      01-OCT-2009

Here is the pseudo-PL/SQL of what I want the query to do:

 SELECT ID, TYPE
 FROM DATA_TABLE
 WHERE ROWNUM = 1 AND STATUS = 'NEW'
 GROUP BY ID, TYPE
 ORDER BY PRIORITY, DATE

I want to grab the next group of ID, TYPE that has a status NEW ordered by priority and date.

In the case above the statement should return either 1 Q or 3 Q, but not both, since they have the same priority and date. If 3 Q was set to STATUS=’DONE’ then the query should return 1 Q.

For the second step I’m going to join this data back in to the table to grab the rows for the set I want to process (eg: 1 Q). This doesn’t have to be a two-step process; if I can grab the set of rows to process without the join that would be ideal.

I hope I’m just missing something really simple, but I’m open to using analytic functions for partitioning if need be.

  • 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-05-13T00:09:55+00:00Added an answer on May 13, 2026 at 12:09 am
    SELECT * FROM (SELECT ID, TYPE FROM DATA_TABLE WHERE STATUS = 'NEW' ORDER BY PRIORITY, DATE) WHERE ROWNUM = 1
    

    That ought to work. You don’t want to group by ID and TYPE because you’re not actually trying to perform any sort of aggregation on the rows matching a given ID and TYPE. If you only cared about one column (say DATE) you could say

    SELECT ID, TYPE FROM DATA_TABLE WHERE DATE = (SELECT MIN(DATE) FROM DATA_TABLE) AND ROWNUM = 1
    

    and avoid sorting the whole table. But I don’t see how to make that work here.

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

Sidebar

Related Questions

My native query below is working fine oracle sqlplus. But through JPA native query,
I am working on a test server with an Oracle 11g installed. I was
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I'm Working with a new Oracle DB, with one table having the following indexes:
Im working in a WebSphere Application Server 7, JDK 1.6 and Oracle 11g. Im
I found out that Oracle Database 10g and 11g treat the following PL/SQL block
I have the following tables in Oracle 11g: Table A SITE_ID SITE_NAME VECTOR .........MANY
I'm working on Oracle and Perl. I have three fields in a table (A,
I'm working on Oracle 10g.One of the column's of my table stores data, as
I'm working on an application which accesses data from an Oracle 11g database. I'm

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.