简体   繁体   中英

Mysql Joining Four Tables After Selecting A column from another table to use as selection Key

在此处输入图片说明

I have the above shown database. I have the following requirement. Suppose I have to get all the data from the four tables small_text_data,big_text_data,file_data where the meta_data_id matches the meta_data_id of group_id =1 in group_meta_data.I mean the input to the function that returns this result is group_id only.So how should I write the join query that selects all meta_data_ids of a particular group and then selects data from all the four data tables. I have tried some join queries.But it is not working.It would be better if I can get a solution in Codeigniter active record.

try this, didnt test

  function get_data($id){
     $query = $this->db
    ->select('g.*, s.*, b.*, f.* ')
    ->join('small_text_data s', 's.meta_data_id=g.group_id', 'left')
    ->join('big_text_data b', 'b.meta_data_id=g.group_id', 'left')
    ->join('file_data f', 'f.meta_data_id=g.group_id', 'left')
    ->where('g.group_id', $id)
    ->get('group_meta_data g');

if($query->num_rows()) {
    return $query->result();
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM