我有兩個表作爲作者和文章。我想獲得每位作者的最新文章列表。我只想爲一位作者撰寫一篇文章。我希望它是最新的。但是,我什至不知道從哪裏開始這個SQL查詢。MySql查詢限制和訂單上加入statament
編輯
我的表結構可以simplefied這樣的:
authors:
id
name
status
seo
articles:
author_id
title
text
date
seo
編輯2
我想出了這樣的事情,有沒有什麼明顯的錯誤,你可以看到在這裏:
SELECT authors.*,
(SELECT articles.title FROM articles WHERE author_id = authors.id ORDER BY articles.date DESC LIMIT 1) as title,
(SELECT articles.seo FROM articles WHERE author_id = authors.id ORDER BY articles.date DESC LIMIT 1) as articleseo
FROM authors
WHERE authors.status = 1
你介意告訴你的數據庫結構嗎?表? –
順便說一句,外鍵不會幫你在這裏 – Mikhail
@GhazanfarMir:已添加。 – yasar