select table1.name,table2.*
from
table1,table2 where table1.userid=table2.userid and table2.id in
(select min(id) as id from table1,table2 where table1.userid=table2.userid)
select * from table2 where id in(
select min(id) as id from table2 group by userid)