0

Hi friends,

I got a table as follows

Name | idNo | started | type | entrytype
-----------------------------------------------------------------
Nick | 12 | 12-02-2011 | 0 | 1
Sam | 14 | 13-02-2011 | 1 | 1
Paul | 12 | 14-02-2011 | 1 | 1
Jwal | 12 | 13-02-2011 | 1 | 1
------------------------------------------------------------------

I want to select using "DISTINCT" I wrote a query as follows

select distinct idNo from table where entrytype='1' order by started LIMIT 0,10

Working but I is not sorting the values according to "started" ( I mean by date )

The following query will sorting the data according to date ..
But I need distinct values .. Please help

select * from table where entrytype='1' order by started LIMIT 0,10

Thanks in advance
Rajeesh

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by crishjeny
2

Your problem is bad database design. By which value would you like the aggregate row with idNo 12 to be sorted - 12, 13, or 14/02/2011?
You cannot have distinct rows as a GROUP BY result and at the same time retrieve the non-grouped values separately. The non-grouped values disappear in any query result with aggregate functions. MySQL does a bad job here by displaying randomly just the first non-aggregate field content it encounters.

Votes + Comments
agree
0

try this ordering

SELECT DISTINCT idNo FROM table WHERE entrytype='1' ORDER BY started asc, started LIMIT 0,10

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.