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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:40:58+00:00 2026-06-04T11:40:58+00:00

Consider the following MySQL tables: APPLICATIONS (contains all applications by all users) unique_id |

  • 0

Consider the following MySQL tables:

APPLICATIONS (contains all applications by all users)

unique_id |  user_id  |  date_of_application  |  date_ended  | score  |  status
--------------------------------------------------------------------------------
1            user_a          2010-09-09          2010-12-24     1.2      Ended
2            user_a          2011-03-03          2011-06-06     1.3      Ended
3            user_a          2011-08-08          2011-10-10     1.0      Ended

4            user_b          2010-09-09          2010-12-24     2.2      Ended
5            user_b          2011-03-03          2011-06-06     1.5      Ended

6            user_a          2012-01-01                                  Active
7            user_b          2012-01-02                                  Active
8            user_c          2012-01-03                                  Active
9            user_d          2012-01-04                                  Active

Desired result:

user_id  |  date_of_application  |  score  |  status
------------------------------------------------------
user_a          2011-01-01           1.0      Active
user_b          2011-01-02           1.5      Active

user_c          2011-01-03           10       Active
user_d          2011-01-04           10       Active

To explain; I want to select/display ALL records that has status = ‘Active’. In addition, those users who are NOT first-time applicants (user_a and user_b) will have their score set to the previous, latest one (see the bolded parts in applications table) with ‘Ended’ status. On the other hand, first-time users (user_c and user_d) will have their score set to 10.

Notes/to reiterate:

  • Assume that score for ‘Ended’ applications/records will always be positive and not null
  • user_c and user_d are first time applicants
  • the applications table will have multiple records of the same users over time, BUT users can only have ONE ‘Active’ application/record at a time

I have the following to start with; this(or a query similar to this) gave me either NULL or 0 values for the score column


SELECT userid_, date_of_application, status,
score = 
(
     SELECT score 
     FROM applications
     WHERE status = 'Ended' AND 
           date_of_application = (SELECT MAX(date_of_application)
                                  FROM applications
                                  WHERE status='Ended')
)

FROM applications

WHERE 
status = 'Active'

ORDER BY 
score ASC,
date_of_application ASC           

What am I missing here?
TIA.

  • 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-04T11:41:00+00:00Added an answer on June 4, 2026 at 11:41 am

    Considering you want the score to be on the basis of latest.
    Try this –

    SELECT apps.user_id, apps.date_of_application, apps.status,
           IFNULL(
                  (SELECT app.score 
                  FROM applications app
                  WHERE  app.user_id = apps.user_id
                  AND app.status = 'Ended' 
                  ORDER BY app.date_ended DESC
                  LIMIT 1), 10) AS score
    FROM applications apps
    WHERE  apps.status = 'Active'
    ORDER BY apps.score ASC,
             apps.date_of_application ASC 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following tables: users messages ----------------- ----------------------- user_id messages msg_id user_id content -----------------
Consider following tables in MySQL database: entries: creator_id INT entry TEXT is_expired BOOL other:
Consider the following two MySQL tables: companies ----------------------- id ticker 1 AA 2 AAPL
Consider the following three MySQL tables: tweets urls tweets_urls --------------------------- --------------------- ---------------- tweet_id text
Consider the following MySQL statement SELECT AccountNumber, Currency, Balance FROM clients JOIN balances ON
Consider following make: all: a b a: echo a exit 1 b: echo b
Consider the following database tables: Table messages with 13,000,000 rows (one row per message).
MySQL server version 5.0.45. Consider the following: ( SELECT CASE WHEN t.group_id = 12
Consider the following 2 tables: Table A: id event_time Table B id start_time end_time
Consider the following situation. I have 3 tables in a resource planning project(created using

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.