Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:06:46+00:00 2026-06-07T03:06:46+00:00

Well, I have two tables community and community_comments. community is the table where the

  • 0

Well, I have two tables community and community_comments.
community is the table where the topic title and other details of the topic is stored.
community_details is the table in which all the posts or comments for the topic/thread is stored.

I need to pull up the latest five topics based on the comments date for threads as well as date of the original topic/thread.

Now there maybe some threads which do not have any comments yet, but are more recent than some threads which do have comments. I need to pull them up correctly.

I tried queries such as

SELECT MAX(community_comments.id), `community`.*
FROM (`community`)
LEFT JOIN `community_comments` ON `community`.`id`=`community_comments`.`community_id`
WHERE `community`.`type` = 1
GROUP BY `community_comments`.`id`
ORDER BY `community_comments`.`date_posted` DESC
LIMIT 5 

this pulls up the same thread multiple times, and this

SELECT MAX(community_comments.id), `community`.*
FROM (`community`)
LEFT JOIN `community_comments` ON `community`.`id`=`community_comments`.`community_id`
WHERE `community`.`type` = 1
GROUP BY `community_comments`.`community_id`
ORDER BY `community_comments`.`date_posted` DESC
LIMIT 5 

pulls up unique threads but doesnt pull up the correct latest ones.

The table structure for community is :

CREATE TABLE `community` (   
  `id` varchar(12) character set utf8 NOT NULL,   
  `title` varchar(255) character set utf8 NOT NULL,   
  `content` text character set utf8 NOT NULL,   
  `author` varchar(13) character set utf8 NOT NULL,   
  `category` int(10) unsigned NOT NULL,   
  `type` tinyint(1) unsigned NOT NULL default '1' COMMENT '1 = Forum; 2 = Site Help; 3 = Local & Global',   
  `location` varchar(100) character set utf8 NOT NULL,   
  `country` int(10) unsigned NOT NULL,   
  `date_posted` datetime NOT NULL,   
  PRIMARY KEY  (`id`)   
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;   

and table structure for community_comments is :

CREATE TABLE `community_comments` (   
  `id` varchar(12) character set utf8 NOT NULL,   
  `community_id` varchar(12) character set utf8 NOT NULL,   
  `content` text character set utf8 NOT NULL,   
  `member_id` varchar(13) character set utf8 NOT NULL,   
  `type` tinyint(1) unsigned NOT NULL default '1' COMMENT '1 = Forum; 2 = Site Help; 3 =  Local & Global',   
  `quoted` varchar(12) character set utf8 NOT NULL COMMENT 'Id number of the comment that is being quoted',   
  `date_posted` datetime NOT NULL,   
  PRIMARY KEY  (`id`)   
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;   

Any help would be greatly appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:06:50+00:00Added an answer on June 7, 2026 at 3:06 am

    So if I’m understanding correctly, you need the community fields that have the 5 most recent community_comments on them. You want to use the SQL Group By to get this right.

    SELECT c.*, MAX(com.date_posted) as last_post
    FROM community c
    LEFT OUTER JOIN community_comments com
    ON com.community_id = c.id
    GROUP BY c.id
    ORDER BY MAX(com.date_posted) DESC
    LIMIT 5
    

    If you don’t want to show communities that have no comments, you can replace the left outer join with an inner join.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one table is the items container, which holds all data
I have two tables which share common fields. Rather than re-map all of these
Well, I have two tables: events : id , title , description trip_events :
I have two tables (well, two relevant for this question) : Bets (holds the
Well interesting to me at least... Say I have two tables: myLookUpTable: lookupId |
I have two tables like so: create table doi ( id number primary key
I have two tables that look as Follows: Person (Table Name) Name1/Phone1/Email1/Address1/Organization1/Notes1 (Fields) Organization
I have two tables: Accounts , which contains the information of accounts that a
Well, i have two tables publica_evento_grupo Field | Type | Null | Key |
Well I m pretty stuck in this problem, I have two tables with identical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.