I have tables Ads
with column AdsId
,ClientId
and table Assigned
. Assigned has AdsId
as foreign key. I want to count the number of AdsId
in Assigned for given ClientId
. I have the following query which works but I am not sure if its the best way. How can I run the same query in yii? Hope I made my question clear.
SELECT A. * , (
SELECT COUNT( B.AdsId )
FROM Assigned AS B
WHERE B.AdsId = A.AdsId
AND A.ClientId =1
)
FROM Ads AS A
WHERE A.ClientId =1
LIMIT 0 , 30