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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:39:20+00:00 2026-06-15T16:39:20+00:00

I was hoping someone can help me out here. I am trying to write

  • 0

I was hoping someone can help me out here.

I am trying to write a query in mysql and i am having a really hard time getting the syntax right. Let me explain what I am trying to do.

I have a table that houses measurement data for construction and each entry has a location_id, room_id, measurement_value, floor_num, measurement_date. I am trying to write a query to get the latest measurement data from each floor (there are only two floors). so I was thinking something like this but I can’t get it to work.

 select bottom_floor.value as bottom_value, top_floor.value as top_value
 from 
 (select measurement_value, measurement_date, floor_num, room_id from rom_measurements where location_id = '1' and floor_num='1' order by measurement_date DESC limit 1) as bottom_floor
 Join 
 (select measurement_value, measurement_date, floor_num, room_id from rom_measurements where location_id = '1' and floor_num='2' order by measurement_date DESC limit 1) as top_floor

So I thought that this would give me back the two values. I have seen that if one of the two subqueries returns an empty set it doesn’t work and I am also pretty sure I have done other things wrong here.

Can someone recommend a better way to accomplish this?

Thanks!

  • 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-15T16:39:21+00:00Added an answer on June 15, 2026 at 4:39 pm

    Total square for all rooms on the floor:

    select square, measurement_date, floor_num
    from room_measurements rm
    join (
      select location_id, floor_num, max(measurement_date) as date, sum(measurement_value) as square
      from room_measurements 
      group by location_id, floor_num    
    ) rm2 
    ON rm.measurement_date=rm2.date AND rm.location_id=rm2.location_id AND rm.floor_num=rm2.floor_num
    WHERE location_id = '1'
    

    Square for each room on the floor:

    select measurement_value, measurement_date, floor_num, room_id
    from room_measurements rm
    join (
      select location_id, floor_num, room_id, max(measurement_date) as date
      from room_measurements 
      group by location_id, floor_num, room_id    
    ) rm2 
    ON rm.measurement_date=rm2.date AND rm.location_id=rm2.location_id AND rm.floor_num=rm2.floor_num AND rm.room_id = rm2.room_id
    WHERE location_id = '1'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really hoping someone can help me out here. I have a DataGrid in
I am out of ideas here, so I'm hoping someone can help. Here is
I am really hoping someone can help me out, because I'm really stuck on
hoping someone can help me out with this. I'm trying to figure out whether
I'm getting very frustrated and I'm hoping someone here can help. I have a
Hoping someone can help me out here, been struggling with this for a little
I am hoping someone can help me out with a problem i am having
Hoping someone can help, i'm trying to work out how to transform an image
I'm hoping someone can help me out here - I'm testing some javascript and
Hoping someone can help me out here. I'm using Google Contacts API to fetch

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.