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

  • Home
  • SEARCH
  • 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 9250977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:34:55+00:00 2026-06-18T10:34:55+00:00

I have two tables ‘Comments’ and ‘Likes’ and I can show all the comments

  • 0

I have two tables ‘Comments’ and ‘Likes’ and I can show all the comments that have been liked and order them by when the comments where added. What I can’t seem to do at the moment is order the comments according to when they were liked.

This is what I have at the moment:

SELECT * 
FROM comments AS c 
WHERE EXISTS (
    SELECT * 
    FROM likes AS l 
    WHERE c.commentID=l.commentID)

Could anyone help me with the SQL to show the comments in order with the one that was most recently liked first and so on…

Just to add – I only want to show the comment once and avoid showing any comments that have not been liked.

  • 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-18T10:34:57+00:00Added an answer on June 18, 2026 at 10:34 am

    If you have multiple likes for a given comment, then you need an aggregation, such as:

    SELECT c.*
    FROM comments c join
         (select l.commentId, MIN(likedate) as FirstLikeDate, MAX(likedate) as MaxLikeDate
          from likes l
          group by l.commentId
         ) l
         on c.commentId = l.CommentId
    order by MaxLikeDate desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I can perfectly query seperately. table1 stores ranges: SELECT
I have two tables that can have multiple records linking to another table, but
I have two tables in my MySQL database, one is a library of all
I have two tables: the primary table, Order, and the other table, Status. Order
I have two tables in my SQL Server db that I want to join:
I have two tables(table_a and table_b) combined with a UNION. How can I check
I have two tables namely locations and pilots. I have been trying to fetch
I have two tables, one that roughly looks like: client_ip server_ip speed --------- ---------
I have two tables which have a column in common, how can I retrieve
I have two tables listings and bids. I have a query that will return

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.