我有两个表作为作者和文章。我想获得每位作者的最新文章列表。我只想为一位作者撰写一篇文章。我希望它是最新的。但是,我什至不知道从哪里开始这个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