i have group of tables this:
post_id | post_content | page_id 1 etc... 7 2 text... 5 and
changelog_id | post_id | page_id | changelog_date | changelog_type 1 2 5 02/02/2015 11:05 3 2 2 5 02/02/2015 11:15 2 3 1 7 03/01/2015 18:15 3 i want return:
select distinct post_id, post_content, changelog_type, changelog_date posts p inner join logs l on l.post_id = p.post_id p.page_id = 5 but distinct wont wort because changelog_date not unique. want return like:
post_id| post_content | changelog_type | changelog_date 2 text... 02/02/2015 11:15 2 with recent entry of post_id page_id , 1 result per post_id.
i tried group by, get:
column 'page.pageid' invalid in select list because not contained in either aggregate function or group clause.
in actual use have 6 tables information , using inner join information them all. need reduce returns getting 1 per instance of post_id.
try this:-
select distinct post_id, post_content, changelog_type, max(changelog_date) posts p inner join logs l on l.post_id = p.post_id p.page_id = 5 group post_id, post_content, changelog_type
Comments
Post a Comment