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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:55:36+00:00 2026-06-16T20:55:36+00:00

I need to update some rows in my table, for simplicity called three. I

  • 0

I need to update some rows in my table, for simplicity called “three”.

I select the columns to update with this query:

SELECT one.id
FROM one 
    JOIN `two` ON ( one.id = two.page )
    JOIN `three` ON ( one.id = three.item )
WHERE two.level = 1
    AND  two.item = (SELECT item FROM two WHERE page = 5 AND level = 1 ) 
    AND three.position > (SELECT position FROM three WHERE item = 5 ) 
ORDER BY three.position

Now I call an update query with id’s I get.

Is there any chance to eliminate the subqueries?

Edit (after Melanie’s comment):

Table “one”:

|id|text|

Table “two”:

|id|item|page|level|

Table “three”:

|item|position|

So when I run the query

SELECT item FROM two WHERE page = 5 AND level = 1

It will return f.ex 1 and the final WHERE clause will be:

two.item = 1 AND two.level = 1

Which is not the same as:

two.level = 1 and two.page = 5

I have the table one – some text with some one.id. I need to update all items from table three which has higher position than my item (f.ex. id = 5) have. But those items should also have the same two.item in table two, where two.page = one.id and level = 1

I am sorry for a poor description.

  • 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-16T20:55:37+00:00Added an answer on June 16, 2026 at 8:55 pm

    You should be able to replace those subqueries by joins:

    SELECT one.id
    FROM one 
        JOIN `two2` ON (two2.page = 5 AND two2.level = 1)
        JOIN `two` ON ( one.id = two.page AND two.item = two2.item )
        JOIN `three2` ON ( three.item = 5)
        JOIN `three` ON ( one.id = three.item AND three.position > three2.position)
    WHERE two.level = 1
    ORDER BY three.position
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to update some rows in a DB table. How I identify the
I need to update some data from another table.. I want to simply take
I need some advice on how to successfully update mutiple rows in my database
I need to update some rows of the tables and then display these rows.
I have a 300.000 rows table; one of the columns is a varchar() but
If you will look at the image above. I need to update this table
I want to update multiple columns using a single query in MySql with some
I need to update tens of thousands rows in SQL table row-after-row. How is
At work, I have a large table (some 3 million rows, like 40-50 columns).
I have a table where I wish to update some of the rows. All

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.