34,838
社区成员




select a.id,b.idb,a.username,b.addrss from a , b
where a.id=b.id
and not exists(select 1 from b t where id=t.id and idB>t.idB)
--or
select a.id,b.idb,a.username,b.addrss from a , b
where a.id=b.id
and (select count(distinct idb) from b t where id=t.id and idB>=t.idB)=1
select A.*,B.*
from A ,
(
select B1.* from B B1,
(select ID,Max(IDB) as IDB from B group by ID) B2
where B1.ID=B2.ID and B2.IDB=B1.IDB
)B
where A.ID=B.ID
select a.*,b.* from a , b
where a.id=b.id
and not exists(select 1 from b t where id=t.id and idB>t.idB)
--or
select a.*,b.* from a , b
where a.id=b.id
and (select count(distinct idb) from b t where id=t.id and idB>=t.idB)=1
假设B有个时间字段.
select a.* , m.* from A,
(
select t.* from b where 时间 = (select max(时间) from B where id = t.id)) m
where a.id = b.id