Broken count(*) after adding LEFT JOIN

Posted by Iain Urquhart on Stack Overflow See other posts from Stack Overflow or by Iain Urquhart
Published on 2010-04-04T15:29:22Z Indexed on 2010/04/04 15:33 UTC
Read the original article Hit count: 174

Filed under:
|
|
|

Since adding the LEFT JOIN to the query below, the count(*) has been returning some strange values, it seems to have added the total rows returned in the query to the 'level':

SELECT `n`.*, exp_channel_titles.*, round((`n`.`rgt` - `n`.`lft` - 1) / 2, 0) AS childs,  
count(*) - 1 + (`n`.`lft` > 1) + 1 AS level,  
((min(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1)) / 2) > 0 AS lower,  
(((`n`.`lft` - max(`p`.`lft`) > 1))) AS upper  
FROM `exp_node_tree_6` `n` 
    LEFT JOIN `exp_channel_titles` 
    ON (`n`.`entry_id`=`exp_channel_titles`.`entry_id`), 
    `exp_node_tree_6` `p`,  
    `exp_node_tree_6`  
WHERE `n`.`lft`  
BETWEEN `p`.`lft`  
AND `p`.`rgt`  
AND ( `p`.`node_id` != `n`.`node_id` OR `n`.`lft` = 1 ) 
GROUP BY `n`.`node_id`  
ORDER BY `n`.`lft`

I'm totally stumped... Thank you!

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql