MySQL Inner Join With LIMIT 到左表
我有这个数据库查询
SELECT *
FROM (`metadata` im)
INNER JOIN `content` ic ON `im`.`rev_id` = `ic`.`rev_id`
WHERE `im`.`id` = '00039'
AND `current_revision` = 1
ORDER BY `timestamp` DESC
LIMIT 5, 5
该查询将结果中的总行数限制为 5。我想将左表元数据
限制为 5,而不限制整个结果集。
我应该如何编写查询?
I have this database query
SELECT *
FROM (`metadata` im)
INNER JOIN `content` ic ON `im`.`rev_id` = `ic`.`rev_id`
WHERE `im`.`id` = '00039'
AND `current_revision` = 1
ORDER BY `timestamp` DESC
LIMIT 5, 5
The query limits the total rows in the result to 5. I want to limit the left table metadata
to 5 without limiting the entire result-set.
How should I write the query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您考虑一下您想要做什么,您实际上并没有针对
元数据
进行选择。您需要首先对其进行子查询。
尝试:
If you think about what you are trying to do, you're not really doing a select against
metadata
.You need to sub query that first.
Try:
这是另一种可能的方法:
这尚未经过测试。如果您在执行此操作时遇到问题,请告诉我 - 我可以详细说明。
Here is another possible approach:
This isn't tested. Please let me know if you run into issue implementing this - and I can elaborate.
好吧,我认为你的意思是
LEFT JOIN
尝试使用LEFT JOIN
而不是INNER JOIN
Well, I think you mean
LEFT JOIN
try usingLEFT JOIN
instead ofINNER JOIN