my query is
SELECT terms.name as artist_name,
wposts.ID,wpostmeta1.meta_value as image
FROM wp_posts wposts
LEFT JOIN wp_postmeta wpostmeta1 ON wposts.ID = wpostmeta1.post_id and wpostmeta1.meta_key = 'fb_thumb'
LEFT JOIN wp_term_relationships ON (wposts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy term_taxonomy ON (wp_term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms terms ON (terms.term_id = term_taxonomy.term_id)
WHERE term_taxonomy.taxonomy = 'category'
AND term_taxonomy.parent = 1160
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
group by terms.name limit 1;
i need to get meta value based on latest post,i was got same terms.name multiple time so i have used group by terms.name but i have problem with meta_value,i am getting first post id meta value instead of latest post id meta value
my attempt was but no luck
LEFT JOIN wp_posts wposts1 ON wposts.ID < wposts1.ID
problem is
how to retrive the last record in each group with wordpress custom query