Hopefully this might help someone else in the future. I'm not sure exactly why it works, but it creates a subquery to select each user defined variable, and an alias for each (which is never used).SELECT x.group_discussion_id, x.comment, x.date_posted, x.username, x.realname, TO_DAYS(NOW()) - TO_DAYS(x.date_posted) AS date_posted_days FROM ( SELECT gdp.group_discussion_post_id, gdp.group_discussion_id, gdp.comment, gdp.date_posted, m.username, m.realname, @recent_post_rank := IF ( @prev_discussion = gdp.group_discussion_id, @recent_post_rank + 1, 1 ) AS recent_post_rank, @prev_discussion := gdp.group_discussion_id FROM group_discussion_posts gdp JOIN members m ON m.memberid = gdp.memberid, (SELECT @prev_discussion:=0) pd, (SELECT @recent_post_rank:=0) rpr WHERE gdp.active = 1 AND gdp.reply_to_post_id != 0 AND gdp.group_discussion_id IN (1, 2, 3) ORDER BY gdp.group_discussion_id DESC, gdp.group_discussion_post_id DESC ) x WHERE recent_post_rank <= 3
In reply to Re^2: Perl DBI not storing @prev_value in query
by Beaker
in thread Perl DBI not storing @prev_value in query
by Beaker
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |