views:

105

answers:

2

Hi,
I have this MySql select query which seems to have a bug but I am quite "green" so I simply cannot see, so maybe you could help?

Here is the query:

SELECT node_id 
  FROM rate 
 WHERE node_id='".$cat_node_id_string."' 
 LIMIT ".$node_count_star.",".$node_count_end."    
 ORDER BY SUM(amount) 
 GROUP BY node_id

Thanks for help in advance...

UPDATE:
I will post a mysql error to make it clearer...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY node_id LIMIT 1,20' at line 5

+2  A: 

try this

SELECT node_id 
  FROM rate 
 WHERE node_id='".$cat_node_id_string."' 
 ORDER BY SUM(amount) 
 GROUP BY node_id
 LIMIT ".$node_count_star.",".$node_count_end."    

Be aware though, that the result will be a single record containing whatever $cat_node_id_string resolves to!

  • With WHERE node_id='".$cat_node_id_string."' you tell MySQL to only return those records where node_id matches an exact string.
  • With GROUP BY node_id you tell MySQL to group all records into one
lexu
A: 

Your error: GROUP BY node_id LIMIT ,'

That comma there suggests that your limit variables $node_count_star and $node_count_end are empty.

Cheers & good luck.

metter
Fixed that but the error stayed...
Povylas