我有两个表competition_registration
和competition_schedule
。我有一个用于从competition_registration
中选择行的选择查询。这是我的代码,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$where = "permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get(); echo $this->db->last_query();exit;
但这显示一个错误。谁能检查这个查询并为我更正?
我想从两个表中选择competition_schedule_id
表中的competition_level_id
和period_id
等于3且competition_schedule
等于6的列。
答案 0 :(得分:1)
希望这对您有帮助:
将competition_schedule.period_id = 6
和这个competition_schedule.competition_level_id = 3
放在where子句中,如下所示:
$this->db->select('competition_registration.permenent_registration_number');
$this->db->from('competition_registration');
$this->db->join('competition_schedule', 'competition_schedule.competition_schedule_id = competition_registration.competition_schedule_id');
$where = "competition_registration.permenent_registration_number is NOT NULL";
$this->db->where($where);
$this->db->where('competition_schedule.period_id' , '6');
$this->db->where('competition_schedule.competition_level_id','3');
//$this->db->join('competition_schedule', 'competition_schedule.period_id = 6');
//$this->db->join('competition_schedule', 'competition_schedule.competition_level_id = 3');
$query = $this->db->get();
echo $this->db->last_query();
exit;
更多信息:https://www.codeigniter.com/user_guide/database/query_builder.html