我有4個表作業,company,employment_type & job_category每個主鍵都是job_id,com_id,type_id,job_cat_id,但是(com_id,type_id,job_cat_id)是作業表的外鍵。查詢內部連接代碼的4個表
我沒有主動記錄工作完美地查詢,這是因爲遵循
select company.com_id, company.company_name, jobs.job_id, jobs.title, jobs.opening_date, jobs.closing_date, jobs.number_of_pos, employment_type.type_id, employment_type.type, job_category.job_cat_id, job_category. category from company inner join jobs on company.com_id=jobs.com_id inner join employment_type on employment_type.type_id=jobs.type_id inner join job_category on job_category.job_cat_id=jobs.job_cat_id
,但如果我嘗試使用codeiginiter活動記錄,如
$this->db->select('company.com_id, company.company_name, jobs.job_id, jobs.title, jobs.opening_date, jobs.closing_date, jobs.number_of_pos, employment_type.type_id, employment_type.type, job_category.job_cat_id, job_category. category');
$this->db->from('company');
$this->db->join('jobs','company.com_id=jobs.com_id','inner');
$this->db->join('employment_type', 'employment_type.type_id=jobs.type_id','inner');
$this->db->join('job_category', 'job_category.job_cat_id=jobs.job_cat_id','inner');
$this->db->order_by('job_id','DESC');
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result_array();
我有以下錯誤
結束You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`) INNER JOIN `jobs` ON `company`.`com_id`=`jobs`.`com_id` INNER JOIN `employmen' at line 1
SELECT `company`.`com_id`, `company`.`company_name`, `jobs`.`job_id`, `jobs`.`title`, `jobs`.`opening_date`, `jobs`.`closing_date`, `jobs`.`number_of_pos`, `employment_type`.`type_id`, `employment_type`.`type`, `job_category`.`job_cat_id`, `job_category`.` category FROM (`company`) INNER JOIN `jobs` ON `company`.`com_id`=`jobs`.`com_id` INNER JOIN `employment_type` ON `employment_type`.`type_id`=`jobs`.`type_id` INNER JOIN `job_category` ON `job_category`.`job_cat_id`=`jobs`.`job_cat_id` ORDER BY `job_id` DESC LIMIT 10
任何幫助將不勝感激
這就是爲什麼我不使用笨的功能,只使用$這 - >分貝 - >查詢()與我自己的書面查詢... – Tschallacka 2013-02-21 10:19:03
以及爲測試目的,您可以使用[this](http://brettdewoody.com/labs/active-check/index.php)來節省您的時間 – 2013-02-21 13:23:45