My table is something like this:
_id time name isNotFirstEntry 1 55555 aaa 0 2 66666 1 3 77777 1 4 88888 bbb 0 5 99998 4 6 99999 4
i.e. for duplicate entries, name is null and the _id of the original entry is stored in isNotFirstEntry.
I want do retrieve _id, time, name, no. of duplicate entries as n where name!=null
I tried something like this:
select _id, time, name, (select count(isNotFirstEntry) from mytable where isNotFirstEntry=_id) as n from mytable where name!=null
but of course that doesnt work. The _id in the nested query is not the same as that of the outside part. I need to access _id of the outside part from the nested query.
Im using android sdk, so i can use sqlite only.
You need to do a join. You can do this as a correlated subquery:
Or as an explicit join with group by: