I got problem with following query. When Im running it in mysql workbench, the user defined variable @cid is being filled correctly, however when i run it in PHP the variable is empty. Im using mysqli_query mechanism.
Its complicated query but as I have already said - works fine in mysql WB but not in PHP. In PHP count is being returned correctly so looks like whole query works except of storing of value in @cid variable.
Query:
SELECT count(*),@cid FROM users WHERE yfid IN
(SELECT viewer_id
FROM views WHERE campaign_id
IN (@cid:=(SELECT * FROM(SELECT campaign_id FROM views
where campaign_id>'$firstCampaignId' AND campaign_id
IN (SELECT id FROM campaigns WHERE owner_yfid
IN (SELECT id FROM uc_users WHERE email='$email'))
group by campaign_id having count(*) > 1
ORDER BY count(*) DESC LIMIT 1) AS tmp)))
AND gender = 1 AND age < 35
EDIT: Ive found out that in MySQL workbench @cid is also NULL when Im running the query for the first time. When Im executing it for the second time, its returned correctly. So probably there is some problem with assigning logic? That is being assigned after excution of query and is accessible on second run?