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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:03:46+00:00 2026-05-23T03:03:46+00:00

select s.s_nric as NRIC , s.s_name as NAME , status.st_status , DATE_FORMAT(status.st_fromdate,’%d-%m-%Y’) as from_date

  • 0
 select s.s_nric as NRIC
      , s.s_name as NAME
      , status.st_status
      , DATE_FORMAT(status.st_fromdate,'%d-%m-%Y') as from_date
      , DATE_FORMAT(status.ST_ON,'%d-%m-%Y') as ST_ON

 FROM si_student_data AS s
   LEFT JOIN si_student_status As st
     ON st.st_nric=s.s_nric
   INNER JOIN
     ( SELECT t.st_nric
            , t.st_fromdate
            , t.st_status
            , MAX(t.st_todate) as ST_ON
       FROM si_student_status t
       GROUP BY t.st_nric
     ) AS status
     ON (  s.s_nric=status.st_nric
       AND status.ST_ON=st.st_todate )
   LEFT JOIN si_student_changes as s1
     ON s1.ch_nric = s.s_nric

   where 1=1
     AND s1.ch_class='2S1'
     AND s1.ch_year='2011'

   GROUP BY s.s_nric

   ORDER BY s1.ch_class
          , s.s_gender
          , s.s_name asc 

When I use this query, I can get maximum date value with respective nric number. But I cannot get other values with related to date. It picked up only the maximum date with defferent row values. I want the related values( status) to the date
my sample table:
First table: si_student_data

s_nric           s_name
1                Suba
2                Felix
3                welcome

Second tabe: si_student_changes

ch_nric            ch_year          ch_class
1                  2011              2S1
2                  2011              2S1
3                 2011               2S1
4                 2010               1A1
5                 2011               2T3
1                 2010               1A1

Third table: si_student_status

st_nric             st_status           st_fromdate              st_todate
  1                      Active             10-10-2011            10-11-2011
  1                      Inactive            11-11-2011            12-12-2011
  1                      PRO                 13-12-2011            22-12-2011
  2                     LWR                  10-10-2011            10-11-2011
  2                     Inactive              11-11-2011            12-12-2011
  2                      ATTR                 13-12-2011           20-12-2011
3                       Active              04-01-2011       10-05-2011                

3 Inactive 11-05-2011 12-08-2011
3 PRO 13-08-2011 20-10-2011

my Expecting output

 s_nric      s_name     st_status  st_fromdate         st_todate
1          Suba       PRO       13-12-2011           22-12-2011
2          Felix      ATTR     13-12-2011           20-12-2011
3          welcome    PRO      13-08-2011           20-10-2011

pls explain how can get maximum date value record. I want maximum date and same row values..

  • 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-23T03:03:47+00:00Added an answer on May 23, 2026 at 3:03 am

    Just add the fields you want from table st. And don’t use the status.* in the SELECT list :

    select s.s_nric as NRIC
         , s.s_name as NAME
    
         , st.st_status
         , DATE_FORMAT(st.st_fromdate,'%d-%m-%Y') as from_date
         , DATE_FORMAT(st.st_todate,'%d-%m-%Y') as ST_ON
    

    So, the whole query could be written as:

     SELECT s.s_nric AS NRIC
          , s.s_name AS NAME 
          , st.st_status
          , DATE_FORMAT(st.st_fromdate,'%d-%m-%Y') AS from_date
          , DATE_FORMAT(st.st_todate,'%d-%m-%Y') AS ST_ON
    
     FROM si_student_data AS s
       LEFT JOIN si_student_status AS st
         ON st.st_nric = s.s_nric
       INNER JOIN
         ( SELECT t.st_nric
                , MAX(t.st_todate) AS ST_ON
           FROM si_student_status t
           GROUP BY t.st_nric
         ) AS status
         ON (  s.s_nric = status.st_nric
           AND status.ST_ON = st.st_todate )
       LEFT JOIN si_student_changes as s1
         ON s1.ch_nric = s.s_nric
    
       WHERE 1=1
         AND s1.ch_class='2S1'
         AND s1.ch_year='2011'
    
       GROUP BY s.s_nric
    
       ORDER BY s1.ch_class
              , s.s_gender
              , s.s_name asc 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this sql: SELECT s.*, u.id, u.name FROM shops s LEFT JOIN users u
Here is my query: select s.*, u.display_name from wp_wdify_sites s, wp_users u LEFT JOIN
I whant to do something like this: SELECT s.name, COUNT(r.request_log_id) AS NumberOfRequests FROM station
I'm running this SQL : SELECT S.name as Owner, T.name as TableName FROM sys.tables
I have an SQL LIKE: SELECT S.*, (SELECT I.NAME FROM institution I, inst_map IM
SELECT S.CLIENT,S.IP_DOMAIN as IP, IFNULL(K.DATE, DATE '0000-00-00') AS RecentDate FROM PLD_SERVERS AS S JOIN
I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
I have the following query SELECT s.name, s.surname, s.id_nr, s.student_nr, s.createdate, s.enddate, (SELECT count(*)
I have this sql query: SELECT S.SEARCH, S.STATUS, C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine,
SELECT s.id, s.show_start, s.show_end, s.bekeken, s.website, s.afbeelding, (SELECT titel FROM serie_details WHERE taalcode =

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.