Improved SQL query for messages and added sample sql file