here's my table msg_to_user
and imagine it's a chat app or a simple forum website
|msg_id|sender_id|receiver_id| subject_id |msg |time |
--------------------------------------------------------------------------
| 1 | 123 | 456 | 3 |"yadda yadd.."|2016-01-31 00:27:16|
| 2 | 456 | 123 | 3 |"ladida .." |2016-01-31 00:37:16|
| 3 | 456 | 123 | 3 |"johndo .." |2016-01-31 01:47:04|
| 4 | 123 | 456 | 3 |"xxxxxx .." |2016-01-31 02:47:04|
| 5 | 456 | 123 | 3 |"qwerty .." |2016-01-31 03:47:04|
| 6 | 789 | 456 | 9 |"dadda kadd.."|2016-01-31 00:11:16|
| 7 | 789 | 456 | 9 |"fadda jadd.."|2016-01-31 00:12:16|
| 8 | 123 | 789 | 9 |"fadda jadd.."|2016-01-31 00:13:16|
below is mysql query, that i use to determine how many, among all the threads i participated in a forum, are the one I actually started:
SELECT *
FROM msg_to_user
GROUP BY subject_id // a given conversation unique id
ORDER BY time ASC
Then i would use a PHP for-loop to check in every mtu_thread who is the first sender.
For instance for the conversation with subject_id = 3 you can see that user 123 actually started the thread
my question is: whether it's possible to just use MYSQL without using PHP