I am beginner with SQL, I'm currently trying to use the HAVING CLAUSE but it does not work..
I have two tables :
tchat :
tchat_message :
So I want the latest messages from the users.
First : I join the tables : `
select user_id, user_message, max(date_message)
from tchat
inner join tchat_message on tchat.id=tchat_message.user_id
here it's ok.
Second : I use the having clause :
select user_id, user_message, max(date_message)
from tchat
inner join tchat_message on tchat.id=tchat_message.user_id
group by user_id
having max(date_message) = date_message`
And here I have an error which says :
Unknown column 'date_message' in 'having clause'
Does anybody have an idea ?