> The year can also be different but Im interested only in the latest year. I
> use the GROUP because I want unique id and if I add year in GROUP BY I can
> get it repeated.

If you're interested in the latest year then your query is totally
wrong because it returns random year. If you saw what you want so far
then you were just lucky. Try to change your query like this:

SELECT id, name, id2, name2, max(year) y
GROUP BY id, name2
ORDER BY name2, y DESC
LIMIT 0, 15


Pavel

On Wed, Jun 30, 2010 at 6:21 AM, J. Rios <jriosli...@gmail.com> wrote:
> On Wed, Jun 30, 2010 at 2:40 AM, Pavel Ivanov <paiva...@gmail.com> wrote:
>
>> > The query return the apropiate values as always the id -> id2 relation is
>> > the same and id -> name and id2 -> name2.
>>
>> So your id maps uniquely to id2, name and name2. But what about year?
>> What value of year do you want to be used in sorting?
>>
>> Anyway try to change query as "GROUP BY id, name2, year". If your id
>> maps uniquely to the year it won't affect results and along with
>> Simon's suggestion it should speed up your query. If your id doesn't
>> map uniquely to year then you are sorting by random number, so you
>> better remove that from ORDER BY clause.
>>
>>
>> Pavel
>>
>>
> There are many entries with the same id and id2 because there are other
> fields with different data but I talked about the ones I need in this query.
> The year can also be different but Im interested only in the latest year. I
> use the GROUP because I want unique id and if I add year in GROUP BY I can
> get it repeated.
>
> Guess my best option is to use a temp table.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to