folumike
(Folumikeidowu)
October 17, 2016, 7:59am
1
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')
weluse
(Jboehnke)
October 17, 2016, 1:10pm
2
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');
folumike
(Folumikeidowu)
October 17, 2016, 1:51pm
3
weluse:
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’
weluse
(Jboehnke)
October 17, 2016, 2:49pm
4
it is an typo in the where function.
that is correctly.
->where('RAND() > 0.667')
i corrected the typo in the upper post.