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

  • Home
  • SEARCH
  • 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 8330903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:15:45+00:00 2026-06-09T02:15:45+00:00

Suppose I have the next table structure, table A: | id | |—-| |

  • 0

Suppose I have the next table structure, table A:

| id |
|----|
| 3  |
| 4  |
| 7  |

Table B:

| id | title | last_id |
|----|-------|---------|
| 1  |   a   |    1    |
| 2  |   b   |    2    |
| 3  |   c   |    3    |

I want to change Table’s B last_id to the next matching id from Table A.

Example: (Referring to Table’s B first row)

Current last_id is 1, So I need to forward it’s value to the next, bigger id from Table A.

So it will go:

1 -> 3 -> 4 -> 7

It can be done also with PHP, but maybe there is a way to keep it in the SQL Server.

Thanks in advance.

NOTE: The server runs MySQL.

  • 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-09T02:15:46+00:00Added an answer on June 9, 2026 at 2:15 am

    Previous answer is correct, but the +1 I believe is no needed as you just need value 7

    UPDATE table_b
       SET last_id = (SELECT MAX(id) FROM table_a)
    

    Edited:

    Now it picks the minimum value from table_a bigger that the last_id on table_b

    UPDATE table_b
       SET last_id = (SELECT MIN(id) FROM table_a WHERE id>last_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to implement charts in my application. Suppose i have a table structure
To be short, suppose I have a string 'next' , next = 123rpq and
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a table with a column name varchar(20) , and I store
Suppose we have a denormalized table with about 80 columns, and grows at the
I have 10,000 rows in database table. I have a view which is suppose
Suppose I have a navigation controller where the next action is to take a
Suppose I have a table that contain information on streaming media connections. In this
Suppose we have this query: ResultSet result = (select * from table_name); Now we

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.