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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:33:35+00:00 2026-05-27T23:33:35+00:00

This is my first post here. My question is similar to a previous thread

  • 0

This is my first post here.

My question is similar to a previous thread albeit different:
mysql converting multiple rows into columns in a single row

What I have is really a large form. There are many forms (sheets, really) and each has the same setup. Each form has labels and values, but the values in the forms can be changed and the forms only display the ”latest” values. The database has a few tables but those important here are the field_labels and the field_values. These two are linked as one might suspect and, the field_value table has a ”date” column.

Now, what I wan’t to do is to select the field_label.id, and the latest value (field_value.fv_value). First I thought this might work fine with CASE but the problem is, CASE stops searching the table immediately after it finds a hit that matches, I want to select the latest hit, not just the first one matched.

The only good idea I had so far is to use a subquery and reform the value table by ordering it first by the (linked) id of the labels, and then by the ”date” of the value. Here’s what I got

SELECT T.msdsid,
       field_label.id,
       (CASE WHEN field_label.id = 1 THEN T.fv_value ELSE NULL END) AS value
FROM (SELECT * FROM field_value ORDER BY field_value.fl_id,field_value.date DESC) AS T
LEFT JOIN field_label ON(T.fl_id=field_label.id)
GROUP BY T.refid;

Now, this does do exactly what I want, but… is there a better way?

Thanks in advance.

  • 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-27T23:33:36+00:00Added an answer on May 27, 2026 at 11:33 pm

    This query will show you the latest values (record) for each field_value.fl_id:

    SELECT fv1.* FROM field_value fv1
      JOIN (SELECT fl_id, MAX(date) date FROM field_value GROUP BY fl_id) fv2
        ON fv1.fl_id = fv2.fl_id AND fv1.date = fv2.date;
    

    Try this query, play with it, and add it into your query.

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

Sidebar

Related Questions

This is my first time here so I hope I post this question at
This is my first post in here and I wouldn't post a question here
This is my first post to this website. Here is my question: I want
This is my first post here and I wanted to get some input from
This is my first post here. I have a problem. I need to take
this is my first post here on stackoverflow and am very impressed by the
Well, this is my first post here and really enjoying the site. I have
My first post here, so i hope this is the right area. I am
Hello all this is my first post here i have been working in an
This is my first post, so please forgive me if this question has been

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.