I'm trying to join tables and getting below error in codeigniter.
Error Number: 1054
Unknown column 'links.client_id' in 'on clause'
SELECT *, `keywords`.`key_id`, `keywords`.`key_name`
FROM (`keywords`)
LEFT JOIN `resources` ON `resources`.`client_id` = `links`.`client_id`
JOIN `links` ON `keywords`.`link_id` = `links`.`link_id`
WHERE `links`.`client_id` = '181' ORDER BY `links`.`link_id` desc
I have Links table and client_id column in there. I also spelt them correctly. Below is the query in link model:
$this->db->select('*');
$this->db->from('links');
$this->db->join('resources', 'resources.client_id = links.client_id', 'LEFT');
$this->db->where('link_id', $link_id);
$query = $this->db->delete('links');
return $query;
What could be wrong?
I think this line is wrong:
LEFT JOIN `resources` ON `resources`.`client_id` = `links`.`client_id`
I am guessing you want something like:
LEFT JOIN `resources` ON `resources`.`client_id` = `keywords`.`client_id`
because you are joining resources
and keywords
You seem to be referring to a column in the links table (links
.client_id
) before you even mention the links table in the query.
Also in the first left join you are joining tables keywords and resources but the related ON clause uses columns from tables resources and clients.