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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:18:19+00:00 2026-05-11T01:18:19+00:00

I am implementing a small queue to handle which process gets to run first.

  • 0

I am implementing a small queue to handle which process gets to run first. I am using a table in a database to do this. Here is the structure of the table (I’m mocking it up in SQLite):

"id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "identifier" VARCHAR NOT NULL , "priority_number" INTEGER DEFAULT 15, "timestamp" DATETIME DEFAULT CURRENT_TIMESTAMP, "description" VARCHAR 

I am trying to write SQL to give me the row of which process can run next. Here is some sample data:

id  identifier  priority_number timestamp             description 1   test1       15              2009-01-20 17:14:49   NULL 2   test2       15              2009-01-20 17:14:56   NULL 3   test3       10              2009-01-20 17:15:03   NULL 4   test4       15              2009-01-20 17:15:08   NULL 5   test5       15              2009-01-20 17:32:23   NULL 6   test6       14              2009-01-20 17:32:30   NULL 7   test7       7               2009-01-20 17:32:38   NULL 8   test8       20              2009-01-20 17:32:57   NULL 9   test9       7               2009-01-21 13:47:30   NULL 10  test10      15              2009-01-21 13:50:52   NULL 

If I use this SQL, I can get the data in the proper order:

select * from queue_manager order by priority_number, timestamp; 

This will give me the item with the lowest priority number (most important) at the top, and in those priority numbers, the earliest into the queue (by timestamp) at the top.

I could run this query, and only take the first row, but I would rather do this with a SQL query that would give me the one row of the process that is at the top of the queue (in the example data above, the row with id=7).

I tried doing self joins and sub queries, but I must be having a mental block – I just can’t seem to get it right.

Thanks in advance!

EDIT

I forgot to mention that I am looking for a database-independent query. I am mocking this up in SQlite, but there is a good possibility I will implement this in DB2 or Oracle. I had thought to use a "limit 1" type operator on my query, but that is different between different database engines.

  • 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. 2026-05-11T01:18:20+00:00Added an answer on May 11, 2026 at 1:18 am

    See if this works:

    select * from queue_manager where priority_number =  (select min(priority_number) from queue_manager) and   timestamp = (select min(timestamp)  from queue_manager qm2  where qm2.priority_number = queue_manager.priority_number) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer wvdschel, while I certainly wish you good luck, consider that… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer In .htaccess this will let you upload a 20MB file,… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer this is the VB code to do so... myListBox.SelectionMode =… May 11, 2026 at 11:52 pm

Related Questions

I am implementing a tree think of it as a folder structure so I
My company is a custom development shop for a number of projects, some larger
I'm implementing a small application in C, which I would like to sell as
I'm developing a small windows app using c++ and i would like to get

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.