Suppose that I have this sql table
Table: Chat
+---------+----------+----------+
| ToUser | FromUser | Message |
+---------+----------+----------+
| 1 | 10 | hi |
| 8 | 1 | yes |
| 2 | 8 | blah |
| 10 | 1 | test |
| 1 | 10 | anything |
| 9 | 4 | hello |
| 2 | 3 | hi |
+---------+----------+----------+
How can I group by ToUser and FromUser where it considers the rows where ToUser = 1 and FromUser = 10 are in the same group of the rows ToUser = 10 and FromUser = 1
I tried the following:
select ToUser, FromUser
from Chat
group by ToUser, FromUser
but this did not help, it considers them different groups.
How can I solve this issue?