gpt4 book ai didi

mysql - 选择Mysql中的倒数第二行

转载 作者:行者123 更新时间:2023-11-29 11:57:33 26 4
gpt4 key购买 nike

我一直在尝试获取 mysql 上的倒数第二行数据。但我的查询只显示最后一行。

SELECT news.news_title, news.news_details, news.news_author, news_images.filename
FROM news JOIN news_images
ON news.news_title = news_images.news_title
ORDER BY news_id DESC LIMIT 1

最佳答案

使用 OFFSET 获取倒数第二个值,例如:

SELECT news.news_title, news.news_details, news.news_author, news_images.filename
FROM news JOIN news_images
ON news.news_title = news_images.news_title
ORDER BY news_id DESC
LIMIT 1 OFFSET 1;

LIMIT number_of_rows OFFSET start_from

如果您想要最后 2 行,请使用:LIMIT 2

编辑:您的问题很不清楚,但请尝试:

SELECT t.news_title, t.news_details, t.news_author, ni.filename
FROM (SELECT news_title, news_details, news_author
FROM news
ORDER BY news_id DESC
LIMIT 1 OFFSET 1) AS t
JOIN news_images ni
ON t.news_title = ni.news_title

关于mysql - 选择Mysql中的倒数第二行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32963585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com