yii2 db\Query

I have this query in mysql and its working perfectly. Please how do I convert it to (new \yii\db\Query())

SELECT distinct b.building_id, b.building_name, t.tariff_id, f.fee_id

            FROM building b INNER JOIN building_tariff t ON (t.tariff_id = b.tariff_id)


            INNER JOIN fee f ON (t.tariff_id = f.tariff_id)


            WHERE RAND() > 0.667


            ORDER BY building_name

I tried this, but I think something is missing

    ->select(['b.building_id, b.building_name, t.tariff_id, f.fee_id']) 


    ->from('building b')


    ->join('JOIN', 'building_tariff t', 't.tariff_id = b.tariff_id')


    ->join('JOIN', 'fee f', 't.tariff_id = f.tariff_id')


    ->where([RAND > 0.667])





    ->orderBy('building_name')

Hi folumike,

i don´t have test it but it think that is correctly.




->select(['b.building_id, b.building_name, t.tariff_id, f.fee_id']) 

->distinct()

->from('building b')

->innerJoin('building_tariff t', 't.tariff_id = b.tariff_id')

->innerJoin('fee f', 't.tariff_id = f.tariff_id')

->where('RAND() > 0.667')

->orderBy('building_name');



Am really grateful for your response. I tried it, but it displays this error

"Use of undefined constant RAND - assumed ‘RAND’

it is an typo in the where function.

that is correctly.




->where('RAND() > 0.667')



i corrected the typo in the upper post.