[34,105]表达式不是有效的条件表达式

时间:2013-12-06 13:53:58

标签: mysql sql jpql

大家好我得到错误:

Exception Description: Syntax error parsing [SELECT u FROM Appointment U WHERE u.startDatetime BETWEEN :date1 AND :date2 INNER JOIN Users_appointment where u.ATTENDEES_USER_NAME LIKE :search]. 
[34, 105] The expression is not a valid conditional expression.

当我尝试运行查询时

public List<Appointment> appointmentRangeSearch(Date startdatetime, Date endDate) {
    Query q = em.createQuery("SELECT u FROM Appointment U WHERE u.startDatetime BETWEEN :date1 AND :date2 INNER JOIN Users_appointment where u.ATTENDEES_USER_NAME LIKE :search");
    q.setParameter("search", "%" + searchString + "%");
    q.setParameter("date1", startdatetime, TemporalType.TIMESTAMP);
    q.setParameter("date2", endDate, TemporalType.TIMESTAMP);
    return q.getResultList();
}

我的想法是我在约会表中搜索一系列日期,然后查看users_appointment表中是否有匹配的用户名,如果是,则输出

出了什么问题?

感谢

1 个答案:

答案 0 :(得分:0)

使用了错误的SQL语法。请仔细阅读SQL语法。您需要使用ON添加JOINING子句,以告诉mysql如何将约会表与users_appointment表链接。我假设你在两个表中都有userid列。

SELECT u FROM Appointment U INNER JOIN Users_appointment 
ON u.userid = users_appointment.userid
WHERE u.startDatetime BETWEEN :date1 AND :date2
AND u.ATTENDEES_USER_NAME LIKE :search