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 8392627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:33:44+00:00 2026-06-09T19:33:44+00:00

dHello can you help me with a query about ordering the topics by most

  • 0

dHello can you help me with a query about ordering the topics by most recent posts? i mean that i want a topic to go on top when someone post on it. Here are the tables:

Discussion

  • id_discution
  • name
  • id_category
  • date

Comments

  • id_comment
  • id_user
  • description
  • type
  • id_discussion
  • date (timestamp)

here is my code but i get duplicates of topics but they are orderd good

select discussion.id_discution, discussion.name, discussion.id_category, 
    discussion.date, discussion.report, comments.id_comment, comments.id_pet_dem_des, 
    comments.date,comments.type 
from discussion,comments 
where discussion.id_discution=comments.id_discussion 
    AND type=3
order by comments.id_comment  desc
  • 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-09T19:33:45+00:00Added an answer on June 9, 2026 at 7:33 pm

    GROUP BY the discussion table’s primary key…

    SELECT
      discussion.id_discution, discussion.name, discussion.id_category, discussion.date, discussion.report
    FROM
      discussion
    INNER JOIN
      comments
        ON  discussion.id_discution = comments.id_discussion
        AND type=3
    GROUP BY
      discussion.id_discution
    ORDER BY
      MAX(comments.date)  desc 
    

    Note: I don’t include any data from the comments table in the SELECT clause.

    This is because you only want each discussion to appear once, but each discussion can have many comments. You either have the discussion appear many times, and include the comments, or you don’t include the comments data in the results.

    You could include aggregate values, such as COUNT(*) to show how many comments there are MAX(comments.date) to show how recently the discussion was commented on, etc, etc.

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

Sidebar

Related Questions

I've created a custom component that display some data to the page according to
I've a sprite that on touch have to start move along the Y coord.
I create a custom image view by extending ImageView that just draws some text
Is it possible to cross-compile D source code for MIPS? For example, I want
I thought for some simple tests that just run a few commands i would
I have 3 activity -scelta -checkin -instarghe form scelta and checkin i can go
I have a simple HTML page that looks like this: ...<div id="main"> <a href="#">Click
From Test.html I include a test.js that runs function d() . This function has
How do I use RIP Relative Addressing in a Linux assembly program for the
I have an xml/tei like <p> In trattoria scoprii che c'era <del rend=tratto a

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.