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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:24:32+00:00 2026-06-04T14:24:32+00:00

I have two tables. threads with the columns ID, forumID, title, content, unixtime comments

  • 0

I have two tables.

“threads” with the columns ID, forumID, title, content, unixtime

“comments” with the columns ID, threadID, content, unixtime

I would like to do a mysql query which sorts all the rows within these two tables based on their unixtime, but also not showing the same “threadID” twice.

The following query will merge the two tables and sort them, but I cant remove duplicates of the threads. I’ve tried with some GROUP BY and DISTINCT, but with no luck.

(SELECT unixtime, ID, threadID FROM comments)
UNION
(SELECT unixtime, ID, forumID FROM threads)
ORDER BY unixtime DESC

Its for showing of the frontpage of a forum, therefor it would make no sense to let the same thread appear more than once.

EDIT: I want to show both the newest comments and the newest threads.

  • 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-04T14:24:33+00:00Added an answer on June 4, 2026 at 2:24 pm
    SELECT unixtime, ID, type, type_id
    FROM (( SELECT unixtime, ID, 'comment' AS type, threadID, forumID
            FROM (  SELECT unixtime, ID, threadID
                    FROM comments
                    ORDER BY unixtime DESC) AS h
            GROUP BY threadID)
            UNION ALL
          ( SELECT unixtime, ID, 'thread', ID, forumID
            FROM threads)
            ORDER BY unixtime DESC) AS h2
    GROUP BY threadID
    ORDER BY unixtime DESC
    

    I changed some stuff. I asume you want to know if it’s a forum or thread id?

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

Sidebar

Related Questions

I have got two tables: threads: id, title posts: id, thread_id, body I want
I am building a forum and I have two tables: Threads ------- ThreadID UsersID
In MySql, I have two tables, A and B. A has as columns A.id,
I have two tables. One that keeps all of my threads started on a
I have two tables linked together through the 3rd table threads: id, name tags:
I have two tables, one for categories and one for threads . I want
i have 3 tables in my site. Users Threads Comments I connected the comments
I have a query like this: SELECT `*` FROM (`threads` t, `members` m) WHERE
I am trying to make a forum post count. I have two tables: Threads
I have this query to search in two SQL tables. I am looking for

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.