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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:36:10+00:00 2026-05-18T04:36:10+00:00

I have 2 tables: The question table with the following structure: id title userid

  • 0

I have 2 tables:

The question table with the following structure:

id
title
userid
date

and answers table with the following structure:

id
idquestion
userid
message
date

I want to show all the questions and the latest answer to that question.

For example, if we have 5 questions, I would like to get something like this:

id    title   message   messagedate
1     qs 1    mess 1    2010-11-18
2     qs 2    mess 2    2010-11-19
3     qs 3    mess 3    2010-11-20
4     qs 4    mess 4    2010-11-21

My query so far:

    SELECT q.id, qa.id as answerid, title, qa.message 
      FROM `questions` q 
INNER JOIN questions_answers qa 
        ON q.id = qa.idquestion 
  GROUP BY q.id 
  ORDER BY q.id, answerid DESC

But it doesn’t work correctly, it groups by the question id(removing all the other columns messages, leaving only the first message – so the order by is useless)

Any help 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-05-18T04:36:11+00:00Added an answer on May 18, 2026 at 4:36 am

    The old problem. Here’s the solution:
    http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html

    In your case:

    SELECT q.id, qa.id as answerid, title, qa.message 
    FROM questions q
    JOIN questions_answers qa ON q.id = qa.idquestion
    LEFT JOIN questions_answers qa2 ON qa.idquestion = qa2.idquestion AND qa.date < qa2.date
    WHERE qa2.idquestion IS NULL
    

    (The idea is to split the problem in two operations: One join from questions to answers and then use the methods from the MySQL article.)

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

Sidebar

Related Questions

I have a base table of Participants and Answers, with the following structure: ParticipantId,
I have a question about tables in MySQL. I'm currently making a website where
I have two tables (well, two relevant for this question) : Bets (holds the
Question for YUI experts... I have a table and I've made each cell of
Another basic Rails question: I have a database table that needs to contain references
I have a query that pulls up questions from one table and answers from
In my database I have tables that define types for example Table: Publication Types
Consider the following table structure: titles(titleID*, titleName) platforms(platformID*, platformName) products(platformID*, titleID*, releaseDate) publishers(publisherID*, publisherName)
I've never used the Global Temporary Tables however I have some questions how they
When I have tables in my database that have PK/FK relationships (int) and when

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.