sql - Use DISTINCT properly joining multiple tables -


select * f_posts  inner join f_topics  on f_posts.post_topic=f_topics.topic_id inner join f_subcategories on f_subcategories.scat_id=f_topics.topic_scat order f_posts.post_date desc limit 0,3 

i list first 3 results, , since last 3 comments in same topic, same topic 3 times. nor distinct nor group seems work.

try:

select p.* , t.*, s.* f_posts p inner join (select post_topic, max(post_date) max_date             f_posts             group post_topic             order max_date desc limit 0,3) m         on p.post_topic = m.post_topic , p.post_date = m.max_date inner join f_topics t on p.post_topic=t.topic_id inner join f_subcategories s on s.scat_id=t.topic_scat order f_posts.post_date desc 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -