Jump to content

ORDER BY 2 Columns in 2 Separate Tables


Hilly_2004

Recommended Posts

Is it possible to display data from 2 separate tables and order the way it's displayed based on 2 columns from the separate tables.

 

e.g.

 

forum_members

 

MEMBER_ID  |  M_FIRSTNAME  |  M_SURNAME  |  M_PROFILEUPDATE

 

submissions

 

MEMBER_ID  |  TITLE  |  SUMMARY  |  TIMESTAMP

 


 

M_PROFILEUPDATE and TIMESTAMP are obviously timestamp records, so hopefully the end goal would be to order the 2 tables based on this columns (the latest being displayed first).

 

Thanks in advance for any help!

 

Link to comment
Share on other sites

Think of it like a "Recent Activity" widget...

 

e.g.

 

Stephen Hill has updated their profile... (2 hours ago...)

 

Charlotte Morley has posted a submission... (3 hours ago...)

 

 

The amount of information displayed above can obviously change depending on how in depth I want it to be, but the above is a good start.

 

Link to comment
Share on other sites

So something like this I guess

(SELECT 'profileUpdate' AS action, CONCAT(M_FIRSTNAME,' ',M_SURNAME) AS userName, M_PROFILEUPDATE AS ts FROM forum_members LIMIT 10)
UNION
(SELECT 'submission' AS action, CONCAT(m.M_FIRSTNAME,' ',m.M_SURNAME) AS userName, s.`TIMESTAMP` AS ts FROM forum_members AS m CROSS JOIN submissions AS s USING (MEMBER_ID) LIMIT 10)
ORDER BY ts DESC
LIMIT 10

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.