I have some tables like this:
USERS TABLE:
| id | created | active | fname | lname |
MESSAGES TABLE:
| id | userId| active | date | content |
I am trying to return some user information, along with the most recently added message for a given user.
Below is the structure of the results that I am rying to achieve:
| userId | userCreated | latestMessageDate| latestMessageContent |
The following query returns the user information:
SELECT
user.id,
user.created
FROM user
WHERE user.active = 1
… But how do I now attach the date of the latest message, along with the actual latest message?
I believe using an inner query is one such approach, but how do you write such a query??
1 Answer