从表中获取最后 200 条记录 [关闭]
Posted
技术标签:
【中文标题】从表中获取最后 200 条记录 [关闭]【英文标题】:Fetching last 200 records from table [closed] 【发布时间】:2015-08-13 05:49:03 【问题描述】:我在数据库中有 1000 多条记录。我需要一个查询来仅选择最后 200 条记录。
SELECT
c.member_id, c.message_id, fm.firstname AS fname, up.gender,
TIMESTAMPDIFF( YEAR, up.dob, NOW( ) ) AS age, c.upload_img, c.image,
c.message_id AS msg_id, c.message AS msg, c.posted_timestamp AS time,
c.topic_id AS topic_id, u.croppedpicture_filename,u.picture_filename FROM
conversation_messages_tbl c, user_profileinformation_tbl up, user_tbl u, family_member_tbl fm
WHERE c.member_id = fm.family_member_id AND
up.user_id = fm.user_id AND
u.emailid = fm.emailid AND
c.topic_id = '1'
GROUP BY c.message_id desc LIMIT 200 sub ORDER BY c.message_id ASC
此查询无法执行。
【问题讨论】:
没问题。到目前为止,您尝试过什么? 你的代码在哪里?我们看不到任何努力。 我投票决定将此问题作为离题结束,因为没有显示任何解决问题的尝试。 Select last N rows from mysql的可能重复 【参考方案1】:包含 order by 子句以获取最后 200 条记录。
SELECT c.member_id,c.message_id, fm.firstname AS fname, up.gender,
TIMESTAMPDIFF( YEAR, up.dob, NOW( ) ) AS age, c.upload_img, c.image,
c.message_id AS msg_id, c.message AS msg, c.posted_timestamp AS time,
c.topic_id AS topic_id, u.croppedpicture_filename,u.picture_filename
FROM conversation_messages_tbl c, user_profileinformation_tbl up,
user_tbl u, family_member_tbl fm WHERE c.member_id =
fm.family_member_id AND up.user_id = fm.user_id AND u.emailid =
fm.emailid AND c.topic_id = '$topicId' GROUP BY c.message_id desc
ORDER BY c.member_id DESC LIMIT 200
【讨论】:
以上是关于从表中获取最后 200 条记录 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章