Re: [sqlite] Limit to 5 records per Group / Top N results per group

2016-06-01 Thread Igor Tandetnik

On 6/1/2016 5:36 PM, Russell, Rory wrote:

In SQLIte, I have 2 tables, one is for a list of Projects (about 50
projects) and the other is a list of key dates for each project. Each
project has about 20 key dates.

How can run a query that will only return the top/first 5 dates for each
project in one query.


Something along these lines, perhaps:

select ProjectName, KeyDate
from Projects p, KeyDates using (ProjectID)
where KeyDate in (
  select d2.KeyDate from KeyDates d2
  where d2.ProjectId = p.ProjectId
  order by d2.KeyDate limit 5);

--
Igor Tandetnik

___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Limit to 5 records per Group / Top N results per group

2016-06-01 Thread Russell, Rory
All,

 

Please help.I have been trying but can't find an answer.

In SQLIte, I have 2 tables, one is for a list of Projects (about 50
projects) and the other is a list of key dates for each project. Each
project has about 20 key dates.

How can run a query that will only return the top/first 5 dates for each
project in one query. 

 

What I am trying to do is get a query that will only return 250 items (ie 50
projects by 5 key dates) max as I am showing these on a report but space is
limited.

 

Thanks,

Rory

___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users