Answer the question
In order to leave comments, you need to log in
A selection of recent comments?
Help a beginner solve this problem:
There are two tables:
users
----------------------
id | name
1 | name1
2 | name2
3 | name3
and comments
-----------------------
id | user_id | text1
| 1 | com1
2 | 2 | com2
3 | 1 | com3
4 | 3 | com4
5 | 2 | com5
6 | 3 | com6
You need to select the name and last comment of all users in one query.
Those. should be:
name1 | com3
name2 | com5
name3 | com6
Thank you in advance!
Answer the question
In order to leave comments, you need to log in
SELECT U.name, C.text
FROM comments C
INNER JOIN users U
ON C.user_id = U.id
AND C.id = (
SELECT id
FROM comments
WHERE user_id=U.id
ORDER BY id DESC
LIMIT 1
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question