Selecting Newest Articles By Unique Authors

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Selecting Newest Articles By Unique Authors

Post by mr_griff »

I am trying to figure out how I can select the most recent articles added to a MySQL table but not repeat any authors.

I have tried this:

Code: Select all

SELECT DISTINCT authorID, articleID, articleTitle FROM articles ORDER BY dateAdded DESC LIMIT 3
But the results will contain repeated authors, which is what I am trying to avoid. Any thoughts...
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Post by Inkyskin »

You could try this way:

Code: Select all

SELECT DISTINCT(authorID), articleID, articleTitle FROM articles ORDER BY dateAdded DESC LIMIT 3
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Maybe you could try to make use of the GROUP BY clause.

Code: Select all

SELECT `tableName`.*, MAX(`tableName`.`dateAdded`) FROM `tableName` GROUP BY `tableName`.`author`;
Post Reply