Wednesday 1 August 2012

Mysql Queries


Msql queries: 


NOT IN :

$query  = $this->db->query('select t.id,t.name from tag as t where t.id  not in (select pt.tag_id  from product_tag  as pt where pt.product_id = ' . $this->uri->segment(3) .')');
  return $query->result();




Left Join:


$query  = $this->db->query('select t.id,t.name from product_tag as p left join tag as t on t.id=p.tag_id where p.product_id=' . $this->uri->segment(3) .'');
  return $query->result();

Two left join :



$queryList = $this->db->query('select p.id,p.mp_from,p.mp_to,p.short_des,p.name,p.status,p.detailed_des,p.image,p.time_updated,c.name as cname,c.id as cid,s.name as sname,s.id as sid from product as p left join category as c on c.id=p.category_id left join sub_category as s on  s.id = p.subcategory_id where p.id =' . $this->uri->segment(3) .'');

return $queryList->result();




No comments:

Post a Comment