Could someone please check my query and the table structures and let me know if there is any way to improve it. I would like some tips for my own personal developmentQuery in PHP:// Load all records so can be displayed in listfunction load_all($page = NULL, $chat_type = NULL){    if(!$page)$page = 1;    $start = ($page - 1) * ITEMS_PER_PAGE_ADMIN;    $query = ;    $query .= SELECT direct_message.*, IFNULL(direct_message_group.staff_id, 0) as staff_id FROM `direct_message`               LEFT JOIN direct_message_group ON direct_message_group.chat_id = direct_message.id               INNER JOIN direct_message_thread ON direct_message_thread.chat_id = direct_message.id               WHERE;    $query .=  (                    (                        direct_message.recipient_id = '.addslashes(session::getAdministratorStaff()->id).'                         OR direct_message.creator_id = '.addslashes(session::getAdministratorStaff()->id).'                        OR (                            direct_message_group.staff_id = '.addslashes(session::getAdministratorStaff()->id).'                            AND direct_message_group.active = '0'                        )                    )                );    $query .=  AND direct_message.school_id = '.addslashes(session::getAdministratorStaffSchoolID()).'                AND direct_message_thread.school_id = direct_message.school_id                GROUP BY direct_message.id                ORDER BY direct_message_thread.inserted DESC LIMIT $start, .ITEMS_PER_PAGE_ADMIN;    $rows = database::select($query);    foreach($rows as $row){        $holding = new direct_message();        $holding->_populate($row);        $this->direct_messages[] = $holding;    }}Table structures:------------------------------------------------------------------------------------------------------
MySQL query to select messages related to a user
performance;php;mysql;join