Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How Do I Insert Only Recently Updated Row From Table1 To 2 in MySQL

How Do I Insert Only Recently Updated Row From Table1 To 2 in MySQL

Scheduled Pinned Locked Moved Database
databasemysqlxmlhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RevathySanthanam
    wrote on last edited by
    #1

    i have two tables with same schema. i have to check table1 for any updates and insert the updates or the entire row into table2, only the most recently updated row.
    so basically, table2 has the unique values from table1; for the duplicate entries in table1, there is only the most recent entry in table2.
    i have tried to get the most recently updated id from table1:

    SELECT distinct id
    FROM table1 order by time_date desc limit 1;

    now i need to use this id to get the other columns from table1 and insert the row with that id, into table2.
    and i have to do this for all the entries in table1.
    i have to update the row in table2 if it already exists, else insert new row. i check for recent record based on the date column, time_date.
    both the tables have same schema.

    any help would be great.!
    thank you.

    Richard DeemingR 1 Reply Last reply
    0
    • R RevathySanthanam

      i have two tables with same schema. i have to check table1 for any updates and insert the updates or the entire row into table2, only the most recently updated row.
      so basically, table2 has the unique values from table1; for the duplicate entries in table1, there is only the most recent entry in table2.
      i have tried to get the most recently updated id from table1:

      SELECT distinct id
      FROM table1 order by time_date desc limit 1;

      now i need to use this id to get the other columns from table1 and insert the row with that id, into table2.
      and i have to do this for all the entries in table1.
      i have to update the row in table2 if it already exists, else insert new row. i check for recent record based on the date column, time_date.
      both the tables have same schema.

      any help would be great.!
      thank you.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You have already posted this question in QA: How Do I Insert Only Recently Updated Row From Table1 To 2[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups