0

I have 2 table in my database. They are admin action table and user action. And have table structure as follows ::

Admin Action table

Action_id |  order    |   Action_type    |           timestamp          |   
   1          12            pending           2014-07-24 15:30:45
   2          12            packing           2014-08-24 14:12:11 
   3          12            shipping          2013-05-01 15:55:12
   4          12            packing           2011-11-25 21:10:22

User Action table

Action_id |  order    |   Action_type    |           timestamp          |   
   1          12            transfer           2014-07-22 15:30:45
   2          12            transfer           2014-09-23 14:12:11 
   3          12            transfer           2013-05-07 15:55:12
   4          12            transfer           2011-11-28 21:10:22

I want to sort timestamp both table. What is come before or after? And Finally. There will be result as follows:

Activity table

Action_id     |   Action_type      |                 timestamp           |
    4               packing                    2011-11-25  21:10:22      //admin action 
    4               transfer                   2011-11-28  21:10:22      //user aciton
    3               shipping                   2013-05-01  15:55:12      //admin action
    3               transfer                   2013-05-07  15:55:12      //user aciton 
    1               transfer                   2014-07-22  15:30:45      //user aciton
    1               pending                    2014-07-24  15:30:40      //admin action
                       .....

What is MySQL command to slove this?

I know I can coding an algorithm in PHP for sort timestamp. But I think if good query from database. It helps to make it easy to handle in the next step.

2
  • what sql query have you tried? Commented Aug 7, 2014 at 6:37
  • ORDER BY timestamp DESC? But it's hard to see what you are trying to do. Commented Aug 7, 2014 at 6:37

1 Answer 1

3

This untested query should give you the expected result:

select * from (
Select * from `Admin Action`
union all
Select * from `User Action`) as a
order by timestamp          
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.