ghostsquad
04-07-2008, 05:22 AM
I'm creating a website and I want to display on my main page the most recent articles that have either been created or updated. Sorted by most recent of either.
Originally I came up with
SELECT
title,text,date_format(created,'%M %e, %Y') AS cf,date_format(updated,'%M %e, %Y') AS uf
FROM `journal_entries`
ORDER BY `updated` DESC,`created` DESC
LIMIT 0, 4
What would happen is, it would take all the "updated" entry, and display them first, regardless of if there was an entry created AFTER the most recently updated entry
for instance, the above query would give me something like this:
+-------------------+------------------+
| cf | uf |
+-------------------+------------------+
| January 1, 2008 | April 6, 2008 |
+-------------------+------------------+
| April 2, 2008 | April 5, 2008 |
+-------------------+------------------+
| April 7, 2008 | NULL |
+-------------------+------------------+
| April 2, 2008 | NULL |
+-------------------+------------------+
| March 18, 2008 | NULL |
+-------------------+------------------+
as you can see row 3 should be listed 1st, followed by 1, 2, 4, 5
I've looked into different things like GROUP BY, MAX(), UNION, nothing seems to be working.
Any help would be appreciated! Thanks!
Originally I came up with
SELECT
title,text,date_format(created,'%M %e, %Y') AS cf,date_format(updated,'%M %e, %Y') AS uf
FROM `journal_entries`
ORDER BY `updated` DESC,`created` DESC
LIMIT 0, 4
What would happen is, it would take all the "updated" entry, and display them first, regardless of if there was an entry created AFTER the most recently updated entry
for instance, the above query would give me something like this:
+-------------------+------------------+
| cf | uf |
+-------------------+------------------+
| January 1, 2008 | April 6, 2008 |
+-------------------+------------------+
| April 2, 2008 | April 5, 2008 |
+-------------------+------------------+
| April 7, 2008 | NULL |
+-------------------+------------------+
| April 2, 2008 | NULL |
+-------------------+------------------+
| March 18, 2008 | NULL |
+-------------------+------------------+
as you can see row 3 should be listed 1st, followed by 1, 2, 4, 5
I've looked into different things like GROUP BY, MAX(), UNION, nothing seems to be working.
Any help would be appreciated! Thanks!