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
https://forums.phpfreaks.com/topic/193692-order-by-2-columns-in-2-separate-tables/
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.

 

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.