android - Getting all records but if some of them are connected then getting only last one -


example table

id | parentid | desc | date 1  |   null   | .... |  1 2  |   null   | .... |  2 3  |    1     | .... |  3 4  |    1     | .... |  4 5  |    2     | .... |  5 6  |   null   | .... |  6 7  |   null   | .... |  7 

okay, want records if of them connected via id <-> parentid, want 1 latest date. result of query table above shold be

id | parentid | desc | date 4  |    1     | .... |  4 5  |    2     | .... |  5 6  |   null   | .... |  6 7  |   null   | .... |  7 

how can in sqllite?

if have api level 16 (jelly bean) or later, following work:

select id,        parentid,        "desc",        max(date) date mytable group coalesce(parentid, id) 

in older android versions, must use correlated subquery filter out records earlier date:

select * mytable not exists (select 1                   mytable t2                   coalesce(t2.parentid,      t2.id     ) =                         coalesce(mytable.parentid, mytable.id)                     , t2.date > mytable.date) 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -