Properly construct the SelectMessageById query.