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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:59:11+00:00 2026-05-26T07:59:11+00:00

Suppose I have the following MySQL table: user_id date_of_application date_ended grade status ————————————————————— 1

  • 0

Suppose I have the following MySQL table:

user_id    date_of_application   date_ended    grade    status    
---------------------------------------------------------------

 1            2011-01-01         2011-02-28     1.0     Ended
 1            2011-02-02         2011-03-28     1.0     Ended
 1            2011-03-03         2011-04-28     (1.5)   Ended

 2            2011-01-01         2011-02-20     2.0     Ended
 2            2011-02-02         2011-03-11     2.5     Ended
 2            2011-03-03         2011-04-28     (1.0)   Ended

 1            2011-05-10              -          -      Pending
 2            2011-05-15              -          -      Pending

  • note that the table can contain multiple records of the same user as long as all its previous applications have ended (status = ended)
  • user_id is not unique
  • date is in yy-mm-dd format
  • date_ended and grade are only updated the instant the application has ended

What I want to accomplish here is to retrieve all rows (together will all columns) WHERE status is ‘Pending’ and such that the value for the grade column for each of these retrieved rows is the value of the latest grade (in parenthesis above) where status is ‘Ended’ for this particular user (or row).

The result:

user_id    date_of_application   date_ended    grade    status    
---------------------------------------------------------------

 1            2011-05-10         2011-06-10     1.5      Pending
 2            2011-05-15         2011-06-15     1.0      Pending

—-EDIT—–:

I’m not sure if I need to create another thread for these additions (‘ will do if I’m advised to do so), anyhow — I decided to go with ypercube’s answer (see below) (which works, minus the commented part). However, in addition to the above resulting table, I also would like to select two more columns (each from a different table):

Working code that gives-off the desired table result (see above):

SELECT user_id
     , date_of_application
     , date_ended
     , ( SELECT te.grade
         FROM TableX AS te
         WHERE te.status = 'Ended'
           AND te.user_id = t.user_id    

         ORDER BY te.date_ended DESC
         LIMIT 1
       ) AS grade
     , status
FROM TableX AS t
WHERE status = 'Pending'

Now I need to select these two other columns (is_first_time_user and name) together with the result table previously mentioned. Note that user_id for both of these tables are unique:

Table2:

user_id    is_firs_time_user
-----------------------------

 1               no
 2               no

Table3:

user_id    name  
----------------------

 1        User A
 2        User B
  • 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-26T07:59:12+00:00Added an answer on May 26, 2026 at 7:59 am
    SELECT user_d
         , date_of_application
         , date_ended
         , ( SELECT te.grade
             FROM TableX AS te
             WHERE te.status = 'Ended'
               AND te.user_id = t.user_id
               AND te.date_ended < t.date_of_application      --- not sure if 
                                                              --- this is needed
             ORDER BY te.date_ended DESC
             LIMIT 1
           ) AS grade
         , status
    FROM TableX AS t
    WHERE status = 'Pending'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following MySQL table result: ID price ------------- 1 10 2
suppose I have a mysql table like following: id value 1 01 2 03
Suppose I have the following student table: id | name | datecreated ------------------------ 1
Suppose I have the following table house: House: id name cityID Where cityID refers
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
Suppose I have a MySQL database named DB, and a table named ContactInfo. The
Suppose I have following string: String asd = this is test ass this is
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following CSS rule in my page: body { font-family: Calibri,
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }

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.