I need to write a query to retrieve values from two columns using mysql table
My table has the following strucutre
| ID | to_user_id | from_user_id | message | datetime |
| 1 | 21 | 07 | hi | 2012-05-10 04:13:01 |
| 2 | 07 | 21 | hello | 2012-05-10 04:17:51 |
| 3 | 21 | 11 | what's up | 2012-05-10 04:21:51 |
| 4 | 21 | 02 | hi dude | 2012-05-10 04:43:51 |
I want to write a query to get only latest message from all from_user_id’s
i will try with
$query="select * from messages WHERE datetime = (SELECT MAX(datetime) FROM messages)";
but it has error shown
Unknown column ‘datetime’ in ‘where clause’
You can also try: