Pregunta

Hi guys i am getting the error :

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.

when i am trying to run the query

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();
}

the idea is that i search for a range of dates in the appointment table and then see if there is a matching username in the users_appointment table and if so output this

what is going wrong ?

thanks

¿Fue útil?

Solución

Wrong SQL syntax used. Please go through the SQL syntax. You need to add a JOINING clause using ON to tell mysql how to link appointment table with users_appointment table. I assume that you have userid column in both tables.

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top