я работаю в частной системе сообщений и у меня есть 3 таблицы, который выглядит, как этотвыбора из трех таблиц в CodeIgniter
БЕСЕДЫ conversation_id | conversation_subject
CONVERSATIONS_MEMBERS conversation_id | user_id | conversation_last_view | conversation_deleted
CONVERSATIONS_MESSAGES message_id | conversation_id | user_id | message_date | message_text
Структура таблицы само за себя. Но я хочу присоединиться ко всем таблицам, выбрать и показать сообщения на странице входящих сообщений.
Я пробовал этот запрос, но я продолжаю получать ошибки. Я новичок в sql; я могу делать простые вещи.
$this->db->select('conversations, conversation_id,conversations, conversation_subject');
$this->db->select_max('conversations_messages.message_date', 'conversation_last_reply');
$this->db->from('conversations');
$this->db->join('conversations_messages','conversations.id=conversations_messages.conversation_id','left');
$this->db->join('conversations_members','conversations.id= conversations_members.conversation_id','inner');
$this->db->where('conversations_members.user_id',$sender_id);
$this->db->where('conversations_members.conversation_deleted','0');
$this->db->group_by('conversations.conversation_id');
$this->db->order_by('conversation_last_reply');
// Get the results from db
$query = $this->db->get();
// Result array contains the records selected
$result_array = $query->result_array();
$ this-> db-> select(); попробуйте это – devpro