You might find what you're looking for in the
API examples. I believe you can simply set your WHERE statement to look something like this:
WHERE MessageSenderUserID = 45 OR MessageRecipientUserID = 45
This would get all messages where user 45 sent or received a message.