Answer the question
In order to leave comments, you need to log in
Mysql query from two interdependent tables
Table Users and Comments
It is necessary to display a list of users who wrote the last comments.
select * from comments as com
left join users as us on com.user_id=us.user_id
group by user_id order by com.date desc LIMIT 0,10
Displays not the latest by comments, but random ones.
if without group by
select * from comments as com
left join users as us on com.user_id=us.user_id
order by com.date desc LIMIT 0,10
then it shows users repeats if they wrote the last 2 comments.
help me please
Answer the question
In order to leave comments, you need to log in
If you need users exactly, then it will be more convenient to take the main query table users:
select distinct us.* from users us
inner join comments com on com.user_id = us.user_id
order by com.date
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question