现在是两张表,比如一个是宠物表 pet, 别一个是宠物寄语表 word,
select * from pet p left join word w ON w.pid=p.id 但是取出来的是主键最少的那个,我要取寄语表中 time最新的那一条,
try this
select * from pet p right join word w ON w.pid=p.id where d.time = (select max(time) from word where word.pid = p.id);
select *
from (
select *
from word w
left join pet p on w.pid=p.id
order by w.time DESC
) where rownum<=1
-------------我的思路是先查出所有的数据并按照 word表中的time字段排序 然后再取第一条数据
select * from pet p right join word w ON w.pid=p.id order by w.time desc limit 1;