我一直试图获取关于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
答案 0 :(得分: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
如果您想要最后两行,请使用: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
答案 1 :(得分:0)
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;