greatest n per group - MySql Left Outer Join limit -
this question has answer here:
table1:
id value 1 2 b 3 c
table2:
xid value 1 1 b 1 c 1 d 1 e 2 f 2 g 2 h 2 2 j 3 k 3 l 3 m 3 n 3 o
select t1.id id, t1.value v1, t2.value v2 (select id table1) t1 left outer join (select xid, value table2) t2 on t1.id = t2.xid
result is:
id v1 v2 1 1 b 1 c 1 d 1 e 2 b f 2 b g 2 b h 2 b 2 b j 3 c k 3 c l 3 c m 3 c n 3 c o
i want limit table2
, 2 rows every matched table1
, below:
1 1 b 2 b f 2 b g 3 c k 3 c l
so, how write sql query?
lots of thanks
Comments
Post a Comment