I have the following table structure:
CREATE TABLE IF NOT EXISTS 'setores' (
'set_cod' int(10) NOT NULL AUTO_INCREMENT,
'set_base' int(10) NOT NULL,
'set_setor' varchar(50) NOT NULL,
'set_data' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
'set_status' enum('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY ('set_cod')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
In this case, I can add 3 levels of sectors, as below:
Wherethisblueisthemainsector,grayrepresentsthesubsectorandwhiterepresentsathirdsector.
Well,myquestionis:HowdoIgetridofthemainsectorbyexcludingallothersectors?WhatifIdeleteonlythesubsector?Isthereanywaytodothisusingleftjoin
?
Tolistasbelow,Ididthefollowing:
#BuscaSetorespublicfunctionbusca_setores(){$this->db->where("set_base", '0');
$this->db->order_by("set_setor", "ASC");
$consulta = $this->db->get('setores')->result();
foreach($consulta as &$valor){
$this->db->where("set_base", $valor->set_cod);
$valor->subsetor = $this->db->get('setores')->result();
foreach($valor->subsetor as &$subsetor){
$this->db->where("set_base", $subsetor->set_cod);
$subsetor->subsubsetor = $this->db->get('setores')->result();
}
}
return $consulta;
}
Can you adapt this reality, to set the exclusion by sector?