GET 24/7 LIVE HELP NOW

Announcement

Announcement Module
Collapse
No announcement yet.

Joining rows based on their timestamp

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Joining rows based on their timestamp

    I'm building a simple message-board like app. For every topic there could be several posts, and I would like to present the topic in a list with some content from the latest post in that topic.
    Simplifying it, say I have two tables:

    Topics:
    - id (INT / AI )
    - subject (VARCHAR(150))
    - created (TIMESTAMP)

    Posts:
    - id (INT / AI)
    - topic_id (INT / FK)
    - content (TEXT)
    - created (TIMESTAMP)

    I want to retrieve rows from the Topics table, along with the latest row for each topic from the Posts table.
    Can anyone suggest the most efficient way of accomplishing this (hopefully without a GROUP BY clause)?
Working...
X