There is a problem with my MySql query. Could you help me out with it?
I have a database as in the picture above, and there are userids that belongs to each user. It should be sorted by type descending. It records the time with the PHP time() function which is written at that moment in the datetime cell within the database. However, the SQL query which I used gives me a result as in the picture below:
SELECT
user.username,
kim.userid,
kim.subject,
count(kim.userid),
max(kim.dateline),
max(kim.rateid)
FROM test as kim
INNER JOIN user
WHERE user.userid = kim.userid
GROUP BY kim.userid limit 10)
Although I get the right results, I’m still having a little problem since the rateid does not show the right subject. So, I’ve been searching for it for two days, and I think there’s a problem that I don't understand or cannot see.
The right query should be like the on in the following picture:
I appreciate if you help!