我有两个表competition_registration
和competition_schedule
。我有 wa 选择查询用于从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
等于 3 且period_id
等于 6competition_schedule
表中。
希望这会对您有所帮助:
把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