我在myBatis映射器中写了一个简单的选择:
<select id="listAllOrders" parameterType="java.util.HashMap" resultMap="commonMaps.detailedOrderResultMap">
select
<include refid="commonSql.fragmentOrderFields" />,
<include refid="commonSql.fragmentSummaryPriceInfoFields" />
from graorder order
left outer join grasummarypriceinfo summarypriceinfo on order.totalPrice_id = summarypriceinfo.id
<if test="userGroupId != null">
where order.userGroupId = #{userGroupId}
</if>
order by order_lastUpdated desc
<if test="limit != null">
limit #{limit}
</if>
</select>
运行此查询时的抱怨是:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntax
ErrorException: You have an error in your SQL syntax; check the manual that corr
esponds to your MySQL server version for the right syntax to use near 'left oute
r join grasummarypriceinfo summarypriceinfo on order.totalPrice_id = su' at line
33
我只是气馁。我在选择中看不到任何错误...
你有任何线索吗?
答案 0 :(得分:1)
您正在使用SQL关键字order
作为表别名。这会导致MySQL出错。例如,我刚在我的一个表上尝试过这个查询:
mysql> select order.film_id, order.title from film order
where order.film_id > 100 limit 4;
并得到了同样的错误:
ERROR 1064 (42000): 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 'where order.film_id > 100 limit 4' at line 1