0

I want to insert last recent three rows in new database?

  +------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
    | time       | userid   | groupid | jobs_running | jobs_pending | job_limit | 
    +------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
    | 1476274005 | achandra |         |            4 |            0 |         0 |            
    | 1476274005 | akawle   |         |           52 |           48 |         0 |                    
    | 1476274005 | apatil2  |         |           20 |            6 |         0 |
    | 1476274793 | snagnoor |         |           17 |           67 |          0 |
    | 1476274793 | snatara2 |         |            0 |           54 |         0 |
    | 1476274793 | sthykkoo |         |            9 |          476 |         0 | 

Expected Output:

        | 1476274793 | snagnoor |         |           17 |           67 |          0 |
        | 1476274793 | snatara2 |         |            0 |           54 |         0 |
        | 1476274793 | sthykkoo |         |            9 |          476 |         0 | 

1 Answers1

1

I think this query will work. db2 is new database and db1 is old from where you have to copy the table

insert into db2.`new_table_name` select * from  db1.old_table order by `time` desc limit 3

ps. This code is untested.

Jagrati
  • 11,474
  • 9
  • 35
  • 56