Reputation: 789
am having two table tbl1(model1-pk-cid) and tbl2 (model2-fk-cid) cid of tbl1 is fk of tbl2 the traditinal sql works but with cdbcriteria it throws exception .am coding it in model1
my traditional query works in phpmyadmin
select fp.*
from tbl1 fp
left join tbl2 fs on fs.cid=fp.cid
where ( fp.cid in (fs.cid) and fp.kat=3)
group by fp.cid
but cdb criteria it throws exception (in model1)
$criteria = new CDbCriteria;
$criteria->join = 'tbl2 as fs ON fs.cid=t.cid';
$criteria->condition = 't.cid IN (fs.cid) and kat='.$id;
$criteria->group = 't.cid';
exception thrown is
SELECT COUNT(*) FROM (SELECT * FROM `tbl1` `t` tbl2 as fs ON fs.cid=cid WHERE cid IN (fs.cid) and kat=3 GROUP BY cid)
am not understanding why is itdointhis
SELECT COUNT(*) FROM (
my query is
(SELECT * FROM `tbl1` `t` tbl2 as fs ON fs.cid=cid WHERE cid IN (fs.cid) and kat=3 GROUP BY cid)
Please let me know am unable to figure out the issue
Upvotes: 0
Views: 92
Reputation: 132
First of all, you missed JOIN keyword:
$criteria->join = 'LEFT JOIN tbl2 as fs ON fs.cid=t.cid';
// ^^^^ ^^^^
Upvotes: 1