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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:17:58+00:00 2026-06-09T18:17:58+00:00

Lets assume i have a table called VISITS containing the following VISIT_DATE (TIMESTAMP) HEIGHT

  • 0

Lets assume i have a table called VISITS containing the following

  • VISIT_DATE (TIMESTAMP)
  • HEIGHT (NUMBER)
  • WAIST (NUMBER)
  • WEIGHT(NUMBER)
  • PATIENT_ID (NUMBER)

    VISIT_DATE| HEIGHT | WAIST | WEIGHT | PATIENT_ID

    10/01/2012 | (null)      | 96      | 130 | 44123

    11/01/2012 | 1.74       | (null)  | 120 | 44123

    12/01/2012 | (null)      | (null)  | 150 | 44123

What I need is a sql select statement to get the most recent value for each column but ignoring the null fields so the output I need would be

The WHERE clause would be

WHERE PATIENT_ID = 44123 ORDER BY VISIT_DATE DESC LIMIT 1

12/01/2012 | 1.74 | 96 | 150 | 44123

As you can see from the output I expect to get from the select I am stepping backwards through each row for the patient until I find a value for each field.

I hope this question is clear and possible, I have searched but haven’t found any real solution up to now, this is going to be used to streamline a medical system being used with hospitals and there is about 100 fields the above is just an example of a few fields to get the concept across of what is required.

  • 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-09T18:18:00+00:00Added an answer on June 9, 2026 at 6:18 pm
    create table VISITS 
    (
      VISIT_DATE TIMESTAMP
    , HEIGHT NUMBER
    , WAIST NUMBER
    , WEIGHT NUMBER
    , PATIENT_ID NUMBER
    );
    
    
    insert into visits values(systimestamp, null, 96, 130, 44123);
    insert into visits values(systimestamp, 1.74, NULL, 120, 44123);
    insert into visits values(systimestamp, null, NULL, 150, 44123);
    
    
    
    
    select 
      last_visit_date
    , height
    , waist
    , weight
    , patient_id
    from
    (
      select 
        first_value( VISIT_DATE) over( partition by patient_id order by visit_date desc) last_visit_date
      , first_value( HEIGHT ignore nulls) over( partition by patient_id order by visit_date desc) height
      , first_value( WAIST ignore nulls) over( partition by patient_id order by visit_date desc) WAIST
      , first_value( WEIGHT ignore nulls) over( partition by patient_id order by visit_date desc) WEIGHT
      , min(visit_date) over( partition by patient_id)  min_visit_date
      , visit_date
      , patient_id
      from visits
    
    )
    where 
      min_visit_date = visit_date
    and patient_id = 44123
    ;
    

    Here is SQLfiddle example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets assume we have this table called visits and it has two fields id
I have a city table that has two columns from_city to_city now lets assume
Lets assume I have 2 XML variables in SQL Server 2008 with the following
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View
Lets assume we have the following code: abstract class Base1 { protected int num;
Lets assume i have a bill number that has 12 numbers: 823 45678912 My
If I have a table with a lot of cells, lets assume 50 rows
I have the following HQL query and for simplicity sake lets assume the mappings
Lets assume we have a table with a fulltext field on it. This field
For the sake of clarity, lets assume I have a table structure like this:

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.