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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:24:31+00:00 2026-05-24T17:24:31+00:00

I have a MYSQL Table with the following structure called daily_measurements +————+———-+——+—–+———————+—————-+ | Field

  • 0

I have a MYSQL Table with the following structure called daily_measurements

+------------+----------+------+-----+---------------------+----------------+
| Field      | Type     | Null | Key | Default             | Extra          |
+------------+----------+------+-----+---------------------+----------------+
| id         | int(11)  | NO   | PRI | NULL                | auto_increment |
| user_id    | int(11)  | NO   |     | 0                   |                |
| date       | datetime | NO   | MUL | 0000-00-00 00:00:00 |                |
| weight     | float    | NO   |     | 0                   |                |
| bicep      | float    | NO   |     | 0                   |                |
| chest      | float    | NO   |     | 0                   |                |
| waist      | float    | NO   |     | 0                   |                |
| neck       | float    | NO   |     | 0                   |                |
| thigh      | float    | NO   |     | 0                   |                |
| hips       | float    | NO   |     | 0                   |                |
| shoulders  | float    | NO   |     | 0                   |                |
| knee       | float    | NO   |     | 0                   |                |
| ankle      | float    | NO   |     | 0                   |                |
| created_on | datetime | NO   |     | 0000-00-00 00:00:00 |                |
+------------+----------+------+-----+---------------------+----------------+

I need to retrieve a list of every user’s weight for there first and last entry.

I’ve tried various combinations of GROUP BY, MIN(date), MAX(date), etc. but I can’t seem to figure out a way to do it efficiently.

The only way I’ve been able to get this to work is to do the following query on the users table, w/ 2 subqueries, but since there are aprox 30,000 users and > 200,000 measurements the query chokes up pretty bad.

SELECT u.id,
(SELECT user_id, weight, date FROM daily_measurements WHERE user_id = u.id ORDER BY date DESC limit 1) as starting_weight,
(SELECT user_id, weight, date FROM daily_measurements WHERE user_id = u.id ORDER BY date ASC limit 1) as ending_weight
FROM users u

Any help would be appreciated.

  • 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-24T17:24:32+00:00Added an answer on May 24, 2026 at 5:24 pm

    My solution:

    SELECT
      u1.user_id,
      u2.first_entry_weight,
      u1.weight             AS last_entry_weight
    FROM daily_measurements u1
      INNER JOIN (SELECT
                    u1.user_id,
                    u1.weight              AS first_entry_weight,
                    u2.fe,
                    u2.le
                  FROM daily_measurements u1
                    INNER JOIN (SELECT
                                  daily_measurements.user_id,
                                  MIN(date_entry)            fe,
                                  MAX(date_entry)            le
                                FROM daily_measurements
                                GROUP BY daily_measurements.user_id) u2
                      ON u1.user_id = u2.user_id
                        AND u1.date_entry = u2.fe) u2
        ON u1.user_id = u2.user_id
          AND u1.date_entry = u2.le
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have MySQL table with the following structure: +---------+--------------+------+-----+---------+----------------+ | Field | Type |
I have the following MySQL table structure: num field company phone website 1 Gas
I have the following MySQL Table Structure: mysql> desc customers; +---------------------+-------------+------+-----+---------+-------+ | Field |
I have following table structure. town: id (MEDINT,PRIMARY KEY,autoincrement), town(VARCHAR(150),not null), lat(FLOAT(10,6),notnull) lng(FLOAT(10,6),notnull) i
I have a MySQL table with a structure like the following: I'm looking for
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a MySql table having the following structure: ontology_term pathway_id pathway_name I want
I have a mysql table of the following structure. So the above table stores
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,

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.