![](/img/trans.png)
[英]Select multiple tables with only unique users and ordered by latest id
[英]multiple order by Is it possible to bring the latest (only one) article by module id ordered by date? EXAMPLE
我有這個查詢,我想從模塊訂購時從復雜的連接中獲取最新和最新的文章。
我對stackoverflow大師的問題如下。
是否可以按日期排序的模塊ID帶來最新(僅一個)文章?
SELECT *
FROM articles Article
LEFT JOIN sources Source ON Article.source_id = Source.id
RIGHT JOIN app_sources asrc ON asrc.source_id = Source.id
/*GROUP BY asrc.module*/ -> if I enable this i get only one but no order by date
ORDER BY asrc.module ASC, Article.published_at DESC
這是我的第一個問題,我希望我正確格式化了! 非常感謝
目前是這樣的(2k結果)
published_at title module
2012-08-22 12:16:41 | Archos Gen10: Tablet Productivity | 1
2012-08-22 12:13:22 | Vail Resorts Ski App Gets Racing With Lindsey Vonn | 1
2012-08-22 11:58:06 | The Internet a Decade Later [INFOGRAPHIC] | 1
我希望這樣
published_at title module
2012-08-15 14:37:40 | The Air Force’s New Ultra-Fast Jet Has an Epic Fai... | 1
2012-01-13 16:17:51 | Canada’s Helium Digital shows us the thinnest iPad... | 2
2012-01-13 14:40:14 | ESPN Feels Lonely: A Chat Regarding ESPN’s Role In... | 3
如果沒有看到你的桌面結構,很多都會被猜測。 但似乎您需要在published_at
字段中包含MAX()
。
像這樣的東西:
SELECT *
FROM
(
SELECT max(published_at) maxDate, source_id
FROM articles
GROUP BY source_id
) Article
LEFT JOIN sources Source
ON Article.source_id = Source.id
LEFT JOIN app_sources asrc
ON Source.id = asrc.source_id
ORDER BY asrc.module ASC, Article.maxDate DESC
如果您想要更明確的答案,則需要提供更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.