How to join four tables with MySQL -


i have omc_projects, omc_logs,omc_specs , omc_files.

all of omc_logs,omc_specs , omc_files table has field called project_id.

create table if not exists `omc_projects` (   `id` int(10) not null auto_increment,   ...   primary key (`id`) ) ... ;  create table if not exists `omc_files` (   `id` int(11) not null auto_increment,   `project_id` int(11) not null,  ...   primary key (`id`) ) ... ;   create table if not exists `omc_logs` (   `id` int(10) not null auto_increment,   `project_id` int(10) not null,   ...   primary key (`id`) ) ... ;   create table if not exists `omc_specs` (   `id` int(10) not null auto_increment,   `project_id` int(10) not null,   ...   ...   primary key (`id`) ) ... ; 

now making delete function in model check if there files, specs or logs this.

function checkproject($id){ // if there data in 1 of table, returns true   $query = 'select omc_projects.id, omc_specs.id, omc_logs.id, omc_files.id omc_projects join omc_specs          on omc_specs.project_id = omc_projects.id join omc_logs         on omc_logs.project_id = omc_projects.id join omc_files         on omc_files.project_id = omc_projects.id omc_projects.id = $id'          $query = $this->db->get();         if ($query->num_rows() > 0){                               return true;         }else{             return false;         }         $query->free_result();       } 

if there 1 data in table, want return true, , if there none returns false.

however works if there data in tables. if there 1 in specs or other tables, not return true.

how should join these tables? left or inner ??

thanks in advance.

you should use outer join.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

asp.net - call stack missing info on mono with apache and mod_mono -