I have a simple chat table with:
id, sender_id, sender_name, recipient_id, recipient_name, content
Trying to group all chats that have happened between Person A (me) and (someone else) OR (someone else) and Person A
How would someone do this ?
EDIT
Goal is to get list with all Chats where Person A is in and only list the other people.
i.e. If Person A has chats with Person B, Person C and Person D I want to show a list with Person B, Person C and Person D. Then in the next view I will show the chats with Person A and someone else.
EDIT:
Technically, you are not really ‘grouping’ in the SQL sense, you may be Ordering the results.
something like this:
also, please do consider normalizing now rather that later. your idea of ‘not querying twice’ is not correct. it will be better to not repeat the names.