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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:23:36+00:00 2026-05-27T08:23:36+00:00

I am trying to convert the following table into something the is a bit

  • 0

I am trying to convert the following table into something the is a bit easier to query. The historical data is important so it cannot get thrown away and there is an indefinite number of options for Variable (I only need some of them in the final result).

This is almost exactly what I need to do but it doesn’t account for the historical data and assumes that the Variables are unique to the User_ID in my case a user_ID may have 3 or 4 of the same variable and I need the newest one.
See > MySQL Pivot Table

| UUID   |UUID_User |Variable  |Value     |DateSet              |
|--------|----------|----------|----------|---------------------|
| X123Y  |123XX12   |FirstName |Jane      | 2011-07-09 14:13:12 |
| X126Y  |123XX12   |LastName  |Jones     | 2011-07-09 14:13:12 |
| X173Y  |123XX62   |FirstName |Joe       | 2011-07-09 14:11:12 |
| X143Y  |123XX62   |LastName  |Smith     | 2011-07-09 14:11:12 |
| X129Y  |123XX12   |LastName  |Smith     | 2011-11-09 14:13:12 | << Jane Gets Married

Transform the above into (making sure to use the newest lastname entry for jane)

|UUID_User |FirstName |LastName  |
|----------|----------|----------|
|123XX12   |Jane      |Smith     |
|123XX62   |John      |Smith     |
  • 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-27T08:23:37+00:00Added an answer on May 27, 2026 at 8:23 am

    Getting the most recent entry per user is a common problem that is often tagged greatest-n-per-group on Stack Overflow. I suggest creating a VIEW for this, though it isn’t strictly necessary.

    CREATE VIEW LatestKeyValue AS
     SELECT k1.*
     FROM KeyValue AS k1
     LEFT OUTER JOIN KeyValue AS k2
      ON (k1.UUID_User, k1.Variable) = (k2.UUID_User, k2.Variable) 
      AND k1.DateSet < k2.DateSet
     WHERE k2.DateSet IS NULL
    

    Then you can pivot that for each variable you need in a couple of different ways such as the following:

    SELECT UUID_User, 
      MAX(CASE Variable WHEN 'FirstName' THEN Value END) AS FirstName,
      MAX(CASE Variable WHEN 'LastName' THEN Value END) AS LastName
    FROM LatestKeyValue
    GROUP BY UUID_User
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert following table data into nested array using PHP. I
I am trying to convert the following SQL into a LINQ expression SELECT COUNT(ID)
I'm trying to convert the following list into a select list so it can
I am trying to convert a php/mysql generated table into a downloadable csv file.
Trying to convert the following but am having difficulty. Can anyone see where I'm
I'm trying to convert the following jquery to javascript syntax, but being not familiar
I am trying to convert the following stored proc to a LinqToSql call (this
So I'm a Flash guy and I'm trying to convert the following code to
HI, I am trying to convert the following vba code to c# and i
I'm trying to use strtotime to convert the following date: 07/09/2009 17:01:27 It's the

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.