Unfortunately this is a query that combines rows from three different tables. One table calls is searchDate, another table calls is dateAdded, etc. So I think I’m forced to either sort with this string version, or use PHP to format how the date shows.
SELECT date_format(answerDate, ‘%m-%d-%Y %l:%i %p’) as date
, cID AS ID
, ‘campaign’ AS source
, campaign AS type
, answer AS entry
FROM campaigns
WHERE uID = ‘$uID’
UNION ALL
SELECT date_format(searchDate, ‘%Y-%m-%d %l:%i %p’) as date
, sID as ID
, ‘searches’ AS source
, type
, keyword
FROM searches
WHERE author = ‘$uID’ limit 5
UNION ALL
SELECT date_format(dateAdded, ‘%Y-%m-%d %l:%i %p’) as date
, cID as ID
, ‘communications’ AS source
, type
, entry
FROM communications
WHERE uID = ‘$uID’
UNION ALL
SELECT date_format(payDate, ‘%Y-%m-%d %l:%i %p’) as date
, paymentID as ID
, ‘payments’ AS source
, type
, frequency
FROM payments
WHERE uID = ‘$uID’
ORDER
BY date desc
, source;
SELECT DATE_FORMAT(answerDate, '%m-%d-%Y %l:%i %p') as date
, [COLOR="#0000FF"]answerDate AS sort_date[/COLOR]
, cID AS ID
, 'campaign' AS source
, campaign AS type
, answer AS entry
FROM campaigns
WHERE uID = '$uID'
UNION ALL
SELECT DATE_FORMAT(searchDate, '%Y-%m-%d %l:%i %p') as date
, [COLOR="#0000FF"]searchDate AS sort_date[/COLOR]
, sID as ID
, 'searches' AS source
, type
, keyword
FROM searches
WHERE author = '$uID' [COLOR="#FF0000"]-- limit 5 is invalid here[/COLOR]
UNION ALL
SELECT DATE_FORMAT(dateAdded, '%Y-%m-%d %l:%i %p') as date
, [COLOR="#0000FF"]dateAdded AS sort_date[/COLOR]
, cID as ID
, 'communications' AS source
, type
, entry
FROM communications
WHERE uID = '$uID'
UNION ALL
SELECT DATE_FORMAT(payDate, '%Y-%m-%d %l:%i %p') as date
, [COLOR="#0000FF"]payDate AS sort_date[/COLOR]
, paymentID as ID
, 'payments' AS source
, type
, frequency
FROM payments
WHERE uID = '$uID'
ORDER
BY [COLOR="#0000FF"]sort_date [/COLOR]DESC
, source;
Well, I guess I need to clarify. Limit five actually limits the results from that table to 5, but I can’t do an order by clause, so therefore it’s not the 5 most recent searches in the search table. Does that help you understand my situation?