Hello Friends,

I have a table which says stores 4 values
id,publisher name,bookname,time

I am firing query like

SELECT * from table where time>='sometime' group by `publisher name` order by time DESC

What I want is to select results in DESC order of time with unique publisher name.
When I fire this query, it gives me unique publisher name but time is reverse ordered, I mean it execute group by first and hence order by time doesnt take any effect.

Can any one siggest the right queyr which will give me most recent(time wise) unique listings.

Hemanshu

Nevermind

MAX(time) as time did the trick

GROUP BY isn't intended for use like this, it's supposed to be used with a MySQL function like COUNT() or MIN() to return information about a resultset from multiple rows. If you want everything sorted by publisher name first, then by time, you simply need to run the query ordered by two columns:

SELECT * FROM `table` WHERE `time` >= 'sometime' ORDER BY `publisher_name` DESC, `time` DESC
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.