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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:37:59+00:00 2026-05-19T03:37:59+00:00

This is currently my MySQL UPDATE query, which is called from program written in

  • 0

This is currently my MySQL UPDATE query, which is called from program written in Java:

String query = "UPDATE maxday SET DatePressureREL = (SELECT " + 
   "Date FROM ws3600 WHERE PressureREL = (SELECT MAX" +
   "(PressureREL) FROM ws3600 WHERE Date >= '" + Date + 
   "') AND Date >= '" + Date + "' ORDER BY Date DESC LIMIT 1), " +
   "PressureREL = (SELECT PressureREL FROM ws3600 WHERE " + 
   "PressureREL = (SELECT MAX(PressureREL) FROM ws3600 " +
   "WHERE Date >= '" + Date + "') AND Date >= '" + Date + 
   "' ORDER BY Date DESC LIMIT 1), ...";

try {
    s.execute(query);
} 
catch (SQLException e) {
    System.out.println("SQL error");
}
catch(Exception e) {
    e.printStackTrace();
}

Let me explain first, what does it do. I have two tables, first is ws3600, which holds columns (Date, PressureREL, TemperatureOUT, Dewpoint, …). Then I have second table, called maxday, which holds columns like DatePressureREL, PressureREL, DateTemperatureOUT, TemperatureOUT,… Now as you can see from an example, I update each column, the question is, is there a faster way? I am asking this, because I am calling MAX twice, first to find the Date for that value and secondly to find the actual value. Now I know that I could write like that:

SELECT Date, PressureREL FROM ws3600 WHERE PressureREL = 
  (SELECT MAX(PressureREL) FROM ws3600 WHERE Date >= '" + 
  Date + "') AND Date >= '" + Date + "' 
ORDER BY Date DESC LIMIT 1

That way I get the Date of the max and the max value at the same time and then update with those values the data in maxday table. But the problem of this solution is, that I have to execute many queries, which as I understand takes alot more time compared to executing one long mysql query because of overhead in sending each query to the server.

If there is no better way, which solution beetwen this two should I choose. The first, which only takes one query but is very unoptimized or the second which is beter in terms of optimization, but needs alot more queries which probably means that the preformance gain is lost because of overhead in sending each query to the server?

  • 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-19T03:37:59+00:00Added an answer on May 19, 2026 at 3:37 am

    Doing 2 queries isn’t really a problem for me, but they should be in a transaction (the reads and the write), this way you’ll be sure that your update values are not wrong. With one query you do not have this problem.

    I think the time lost in reading some data is nothing regarding the time lost by performing a write operation. A write operation is not by definition a fast thing, you could have triggers, you’re maybe emptying the query cache from all requests impacting this table, the database needs to sync your write on disk, etc.

    The more important thing for you is to keep your process simple, readable, and logic.

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

Sidebar

Related Questions

I have a relatively complex .htaccess file to control page requests, this currently redirects
Currently this expression I ([a-zA-z]\d]{3} returns when the following pattern is true: I AAA
I currently use this function to wrap executing commands and logging their execution, and
The code currently does this and the fgetpos does handle files larger than 4GB
I am currently receiving this error: Validation of viewstate MAC failed. If this application
I am currently testing this in Mozilla FireFox 3.0.5 using FireBug 1.3.0 with jQuery
I do not currently have this issue , but you never know, and thought
As I am currently doing this project in only C, I've up untill this
There is probably is simple fix for this but I currently have code similar
This is what I currently have: CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON

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.