slevin10
(Slevin10)
May 19, 2014, 11:33am
1
i have 3 tables
"worker","activity" and linking table "workerToActivity"
activity has ‘time’ and ‘activity_id’ Columns
worker has ‘worker_id’ Column
workerToActivity has ‘worker_id’ and 'activity_id’Columns
in my query i want to get all workers that are not register to activity in certain time,
i dont know how to do that
can u help me?
konapaz
(Konapaz)
May 19, 2014, 12:49pm
2
In my cases in the past I used something like that
http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-options
http://www.yiiframework.com/forum/index.php/topic/10185-using-relations-and-conditions
But when the queries became more comblex I use this one
Yii::app()->db->createCommand('a comblex query')->queryAll()
So you have to check both of two options
joblo
(Joe)
May 20, 2014, 8:31am
3
SELECT a.*
FROM worker a
LEFT JOIN workerToActivity b ON b.worker_id=a.worker_id
LEFT JOIN activity c ON c.activity_id=b.activity_id
WHERE b.activity_id IS NULL --no activity assigned
OR NOT (c.time BETWEEN .. AND ..)
slevin10
(Slevin10)
May 21, 2014, 8:02am
4
conapaz & Joblo
u both help me alot, thnks.