Find greatest in multiple groups across tables MySQL -
i have table called packages contains data , related table contains other information. it's set this:
name|version|architecture|date|id
and in second table called distribution have this:
repo|id
the id's reference each other. want able newest (ordered date) grouping. want group name, architecture, , repo. problem can't seem normal greatest-n-in-group work right because have go across tables. have far
select p1.name, p1.version, p1.arch, d1.repo, p1.date packages p1 inner join distribution d1 on p1.id = d1.id inner join ( select name, arch, repo, max(date) date packages inner join distribution on packages.id = distribution.id group name, arch, repo ) sq on p1.name = sq.name , p1.arch = sq.arch , d1.repo = sq.repo , p1.date = sq.date
the problem doesn't seem group repo correctly. doesn't give me unique repo.
edit: want newest version each repo. have max date in each repo, , groups.
edit 2: worked 1 answer bit this:
select p1.name, p1.version, p1.arch, d1.repo, p1.date packages p1 inner join distribution d1 on p1.id = d1.id inner join ( select name, arch, repo, max(date) date packages inner join distribution on packages.id = distribution.id group name, arch, repo ) sq on p1.name = sq.name , p1.arch = sq.arch , d1.repo = sq.repo , p1.date = sq.date
and seems working me.
i think want remove repo
max query:
select p1.name, p1.version, p1.arch, d1.repo, p1.date packages p1 inner join distribution d1 on p1.id = d1.id inner join (select name, arch, max(date) date packages group name, arch ) sq on p1.name = sq.name , p1.arch = sq.arch , p1.date = sq.date;
edit:
if not repos have date, want filter distribution in subquery. however, still don't want put repo
in aggregation:
select p1.name, p1.version, p1.arch, d1.repo, p1.date packages p1 inner join distribution d1 on p1.id = d1.id inner join (select name, arch, max(date) date packages p join distribution d on p.id = d.id group name, arch ) sq on p1.name = sq.name , p1.arch = sq.arch , p1.date = sq.date;
Comments
Post a Comment