Welcome Guest, Not a member yet? Register   Sign In
MySQL: aliased fields return value of just one field
#1

[eluser]codex[/eluser]
Consider this query:

Code:
SELECT fc.*, COUNT( fp.forum_post_id ) AS total_posts,
COUNT( fp2.forum_post_id ) AS total_replies

FROM forum_categories AS fc
LEFT JOIN forum_posts AS fp ON fp.forum_cat_id = fc.forum_cat_id AND fp.post_parent_id = 0
LEFT JOIN forum_posts as fp2 ON fp2.forum_cat_id = fc.forum_cat_id AND fp2.post_parent_id != 0
GROUP BY fc.forum_cat_id

total_posts and total_replies should yield different results, but instead I get the same result for both. Obviously there's something not quite right with this query, but I don't understand what. I have the 2 aliased differently, so what could be the problem?

Are AND's allowed in joins?


Messages In This Thread
MySQL: aliased fields return value of just one field - by El Forum - 01-30-2008, 11:43 AM
MySQL: aliased fields return value of just one field - by El Forum - 01-30-2008, 12:37 PM
MySQL: aliased fields return value of just one field - by El Forum - 01-30-2008, 12:47 PM
MySQL: aliased fields return value of just one field - by El Forum - 01-30-2008, 12:59 PM
MySQL: aliased fields return value of just one field - by El Forum - 01-30-2008, 01:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB