Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013
    Posts
    1

    Unanswered: Need help on a query

    Hey,

    I am stuck with a SQL statement. I have 2 tables:

    user: user_id (PK), displayname
    message: id (PK), sender_id (FK to user_id), receiver_id (FK to user_id), message

    Im trying for like 3 hours to get this:

    Get a list of the last messages from each user.

    I was trying hard with MAX(message.id) but failed miserably

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    SELECT *
       FROM message
       WHERE  id = (SELECT Max(z.id)
          FROM message AS z
          WHERE  z.sender_id = message.sender_id)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •