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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:40:12+00:00 2026-05-28T13:40:12+00:00

Her are my table structures: Table1:track_data | device_id(foreign) | latitude | longitude | activity

  • 0

Her are my table structures:

Table1:track_data

| device_id(foreign) | latitude | longitude | activity |

-Stores id, location co-ordinates, activity being the time instant they were inserted.


Table2:user_devices

| device_id(primary) | park_lat | park_long |

Stores id, park_lat/park_long need to be stored with latitude/longitude from track_data table on request(i.e., the latest activity data).
Now, how will i store the latest latitude/longitude from Table1 to Table2, in a single query. Is this possible, To mix select and update in same query?

And now my non-functioning intuitive query:)

UPDATE user_devices,track_data
SET user_devices.park_lat = latitude,user_devices.park_long = longitude  
WHERE user_devices.id='33' AND track_data.activity=(SELECT activity FROM track_data 
ORDER BY track_data.activity DESC LIMIT 1)
  • 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-28T13:40:12+00:00Added an answer on May 28, 2026 at 1:40 pm
    update user_devices 
    join (select device_id, latitude, longitude, activity
          from (select device_id, latitude, longitude, activity
              from track_data order by device_id, activity desc) x
          group by device_id) latest_lat_long on latest_lat_long.device_id = user_devices.device_id
    set 
    park_lat = latest_lat_long.latitude,
    park_long = latest_lat_long.longitude;
    

    How this works:

    • The inner-most query orders by device_id then activity latest first
    • The next layer gets just the first record for each device_id (the latest, because we ordered it thus)
    • We then join this to our table so we only need one pass over track_data
    • Finally we update the columns

    This query will perform very well, because it isn’t doing a query per row like some people would instinctively do.

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

Sidebar

Related Questions

Example:i have a database name base1,with one table(product) and data inside her:productid,name,price. How to
I have a table that stores customer items. The table needs to reflect the
I've got a users table and a votes table. The votes table stores votes
Her is an image showing a the table i have, b the grid i
My client failed her PCI compliance audit. The server supports Remote Desktop (Terminal Service)
I'm developing web app that user can save his/her work to server. The data
I need help explaining to my boss why her design is poor on a
How can I present a control to the user that allows him/her to select
I've been tasked (by my wife) with creating a program to allow her to
I'm writing an app that lets a diabetic user enter his/her blood glucose readings,

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.