views:

44

answers:

1

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!

+1  A: 

If you wonder about a count, just run the query without a group by. You'll see where the rows in the count come from.

In your case, you could probably fix it by changing count(*) to count distinct(n.entry_id).

Andomar
I updated to count(DISTINCT `n`.`entry_id`) and it now produces even stranger results...
Iain Urquhart