[eluser]jurlan[/eluser]
this is the original query:
Code:
$sql = "SELECT DISTINCT c.ID AS CarrierID, c.Title, c.VersionInfo, im.Filename FROM carriers c ";
$sql .= "USE INDEX (PRIMARY) ";
$sql .= "INNER JOIN carriermainartists cm ON cm.CarrierID=c.ID ";
$sql .= "INNER JOIN identities i ON i.ID=cm.IdentityID ";
$sql .= "INNER JOIN dblinking li ON li.ObjectID=c.ID AND li.ObjectType=5 AND li.LinkType=9 AND li.LinkCategory=25 ";
$sql .= "INNER JOIN images im ON im.ID=li.LinkID ";
$sql .= "WHERE((i.Nationality=2) OR (i.ID IN (4356, 77071)) OR (c.Concept=4)) AND (c.Hidden = 0) AND ((c.Filter & 1)=1) ";
$sql .= "AND c.ID='.$randCarrierID.' LIMIT 1";
this is what I've written so far:
Code:
$this->db->distinct();
$this->db->select('c.ID, c.Title, c.VersionInfo, im.Filename');
$this->db->join('carriermainartists cm', 'cm.CarrierID=c.ID', 'inner');
$this->db->join('identities i', 'i.ID=cm.IdentityID', 'inner');
$this->db->join('dblinking li', 'li.ObjectID=c.ID AND li.ObjectType=5 AND li.LinkType=9 AND li.LinkCategory=25', 'inner');
$this->db->join('images im', 'im.ID=li.ID', 'inner');
$this->db->where('i.Nationality', 2)->or_where_in('i.ID', $this->numbers)->or_where('c.Concept', 4);
$this->db->where('c.Hidden', 0)->where('(c.Filter & 1) = 1')->where('c.ID', $randCarrierID);
$this->db->limit(1);
$result = $this->db->get('carriers c');
$data = $result->result();
I'm also wondering if there a way to get rid of the AND's in the dblinking join
And this is the output of my $this->db->last_query();
Code:
SELECT DISTINCT `c`.`ID`, `c`.`Title`, `c`.`VersionInfo`, `im`.`Filename`
FROM (`carriers` c) INNER JOIN `carriermainartists` cm ON `cm`.`CarrierID`=`c`.`ID`
INNER JOIN `identities` i ON `i`.`ID`=`cm`.`IdentityID`
INNER JOIN `dblinking` li ON `li`.`ObjectID`=`c`.`ID` AND li.ObjectType=5 AND li.LinkType=9 AND li.LinkCategory=25
INNER JOIN `images` im ON `im`.`ID`=`li`.`ID`
WHERE `i`.`Nationality` = 2 OR `i`.`ID` IN (4356, 77071) OR `c`.`Concept` = 4 AND `c`.`Hidden` = 0 AND (c.Filter & 1) = 1
AND `c`.`ID` = 18806 LIMIT 1
Thanks!