I have 1000+ records in the database. I need a query to select only last 200 records.
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
This query is failing to execute.
include the order by clause to get the last 200 records.
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