MySQL错误1064(v 5.0.96)GROUP BY子句

时间:2012-11-26 07:45:18

标签: mysql

我习惯在Oracle数据库上运行,所以我不太确定如何解决这个问题。我已将我的查询的一个简单示例缩小到以下内容:

 SELECT 0 as gm_rowID, 
'-ALL Grantmakers-' as grantmakerName 
FROM dual
GROUP BY 2

phpMyAdmin运行SQL时出现以下错误:

#1064 - 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 'ORDER BY 2 LIMIT 0, 30' at line 1

Oracle可以正常运行此查询。 MySQL可以在没有GROUP BY子句的情况下运行查询。有什么想法吗?

- 这是整个查询:

SELECT 
    p.grantmaker_rowid as gm_rowID, 
    gm.grantmaker_companyName as grantmakerName 
FROM grantmaker_info gm, proposal_submission p 
WHERE 0=0 
AND p.grantmaker_rowid = gm.grantmaker_rowid 
UNION 
SELECT 
    0 as gm_rowID, 
    '-ALL Grantmakers-' as grantmakerName
FROM dual 
ORDER BY 2
GROUP BY 2
LIMIT 0 , 30

1 个答案:

答案 0 :(得分:2)

  

为输出选择的列可以使用列在ORDER BY和GROUP BY子句中引用   名称,列别名或列位置。列位置是   整数并从1开始

来自:http://dev.mysql.com/doc/refman/5.0/en/select.html

除非您在该表中只有1列,否则它应运行正常。然而,我的建议是引用您尝试GROUP BY的任何内容的列名(或别名)。

编辑:我唯一的另一个建议是包含该表的SHOW CREATE TABLE输出。

edit2:好的,我看到你已经更新了你的问题。为什么不代替ORDER BY 2ORDER BY grantmakerName(如果这是您想要订购的列?)