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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:07:49+00:00 2026-06-03T22:07:49+00:00

[FYI, this is not homework — I guess everyone thinks that because I made

  • 0

[FYI, this is not homework — I guess everyone thinks that because I made an effort to format my question in a simple readable form? Again, not homework. I’m at work, and just trying to learn. Thanks.]

I’m very stuck on a tricky one. I’m a Java guy, I’m not a SQL guy, so any help with this is GREATLY appreciated!

I have a PROJECT table and a TASK table like so:

**PROJECT**
projectId
name

PROJECT has many TASKs:

**TASK**
taskId
projectId
description
userId // the user who is assigned the task
status // either "IN_PROGRESS" or "COMPLETE"
sequence // the numeric sequence of the TASK in the PROJECT

For example:

Project
   projectId=100
   name="Build House"
Task
   taskId=250 // task IDs are not necessary in numerical order
   sequence=1
   description="Pour Foundation"
   userId=55
   status="COMPLETE"
Task
   taskId=240
   sequence=2
   description="Build walls"
   userId=56
   status="COMPLETE"
Task
   taskId=260
   sequence=3
   description="Install windows"
   userId=57
   status="IN_PROGRESS"
Task
   taskId=245
   sequence=4
   description="Build roof"
   userId=58
   status="IN_PROGRESS"

I need two queries:

(1) For a given projectId, get the ‘current task’. The current task is the task number with the smallest sequence number which is not complete. In my example, getCurrentTask(projectId=100) would return taskId 260 (because it’s the first one that is incomplete).

(2) For a given userId, get the list of projects where he is assigned to a ‘current task’. In my example, getProjectsForUserId(userId=57) would return projectId 100; getProjectsForUserId(userId=58) would return nothing.

  • 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-03T22:07:51+00:00Added an answer on June 3, 2026 at 10:07 pm
    SELECT min(taskID) FROM Task WHERE ProjectID = ? and status <> "COMPLETE";
    
    SELECT projectID FROM 
    Tasks T INNER JOIN
    (SELECT min(taskID) as taskID, projectID FROM Task GROUP BY projectID WHERE status <> "COMPLETE")
    AS CT on CT.taskID = T.taskID
    WHERE T.userId = ?'
    

    EDIT

    The queries below order by sequence, instead of TaskID.

    SELECT taskID from Task T INNER JOIN
    (SELECT min(sequence) as sequence, projectID FROM Task GROUP BY projectID WHERE status <> "COMPLETE")
       AS CT on CT.sequence = T.sequence AND CT.projectID = T.projectID
    WHERE T.projectID = ?;
    
    SELECT projectID FROM 
    Task T INNER JOIN
    (SELECT min(sequence) as sequence, projectID FROM Task GROUP BY projectID WHERE status <> "COMPLETE")
       AS CT on CT.sequence = T.sequence AND CT.projectID = T.projectID
    WHERE T.userID = ?;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(FYI: This question is half thoretical. It is not something which I am definatly
FYI, There is some overlap in the initial description of this question with a
* FYI: I'm not using Adsense and this is not against my TOS... I
FYI This is homework. I have to build a Java Chat server. I have
FYI - This is not MVC. I am using web form authentication and have
I assume this is not deterministic simply because DB_NAME() is not deterministic? If DB_NAME()
I've done this before...not sure what i'm doing wrong now I know it's the
With iPhone, creating your own AppFramework is made impossible by the fact that Apple
Here is my attempt which is NOT tail call optimized because I need to
I have looked everywhere for the answer to this question and while 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.