So, my situation in logics is kind’a bad, and my math is not that good,
so i need your help “building” a query to fetch information from 3 different tables by join query.
my structure is like this:
- Users table : with primary key “ID”
- Campaigns table : with primary key “ID”
- User_Campaign table : with user_id, and campaign_id rows.
I want to pull all the campaigns that doesn’t exist in user_campaign table with the user id X.
my query is for zend framework.
I will appreciate any kind of help, so thanx, and good evening from israel!
my current query:
$q = $this->select()
->setIntegrityCheck(false)
->from(array('c' => 'campaigns'))
->join(array('uc'=> 'user_campaign'), 'uc.campaign_id != c.id AND uc.user_id != 1', array('campaign_id', 'user_id'));
Try this query out, using a left join, and adding a WHERE on the joined table for a valid id being null, will return results that don’t exist on the right side of the join