select a.name,b.password from (select id,name from A order by name) a,B b where a.id=b.id;