2016-09-12 21 views
0

我正在創建日記數據庫。我的表結構有一個名爲journals的列,它對插入的每篇文章都有一個值。現在我想從表中選擇並按date_added進行訂購,但是要跳過從同一日記中選擇任何兩篇文章。當我使用ORDER時,如何從表格中獲取沒有重複的行?

+7

請出示一些示例數據和預期的結果 – TheGameiswar

+1

你有沒有嘗試任何添加以及 –

+0

的ORDER BY無關吧。如果期刊有多篇文章,您想要返回哪篇文章? – jarlh

回答

0

這可能是你在找什麼

select J1.journal, J1.article, J2.DatePublished 
from 
journals J1 
inner join 
(
    select journal, max(publishdate) as DatePublished -- shows only the most recent article 
    from journals 
    group by journal 
    order by DatePublished desc -- date ordered descending for s&g 
) J2 
    on J2.journal = J1.journal 
    and J2.DatePublished = J1.publishdate 
相關問題