php - sum of table's column return null (codeigniter) using left join
975
I have this query:
$get_similar = $this->db->select('product.ar_id, product.title, likes.id, SUM(likes.up) as vote');
$get_similar = $this->db->from('product');
$get_similar = $this->db->join('likes', 'likes.id = product.id', 'left');
$get_similar = $this->db->where("MATCH (product.title, product.introduction) AGAINST ('$search') group by product.id LIMIT 6", null, false);
$get_similar = $this->db->get();
For each row I getvote = null
! It's supposed to return0
for only the products that don't have votes! Can you tell me where I made a mistake, please?
Answer
Solution:
I think your error is here:
you are joining likes.id with product.id, i think you want to join something like "likes.product_id" with "product.id"