fixed chats sql query