select a.dealid
, a.dealname
, a.dealdetails
, b.dcid
, b.commenttime
, b.commentperson
, b.comment
from deals a, dealcomments b
where b.dealid = a.dealid
and b.commenttime = (select max(x.commenttime)
from dealcomments x
where x.dealid = b.dealid)
編輯:我沒看過最初的問題足夠接近,並沒有注意到,都需要在查看所有優惠券行。下面是我的修訂答案:
select a.dealid
, a.dealname
, a.dealdetails
, b.dcid
, b.commenttime
, b.commentperson
, b.comment
from deals a left outer join (select x.dcid
, x.dealid
, x.commenttime
, x.commentperson
, x.comment
from dealcomments x
where x.commenttime = (select max(x1.commenttime)
from dealcomments x1
where x1.dealid = x.dealid)) b
on (a.dealid = b.dealid)
你想要什麼,如果對於一些交易有兩個或更多最後的評論與完全相同的時間? – 2009-07-04 23:22:58