SELECT M.*, hasAttachments = EXISTS(SELECT AttachmentId FROM Attachment WHERE messageId = M.messageId), FROM Message M