-1
SELECT person.first_name, person.last_name, meeting.meeting_id, meeting.meeting_start, meeting.meeting_end
-> FROM person INNER JOIN (meeting
-> INNER JOIN person_meeting ON meeting.meeting_id = person_meeting.meeting_id)
-> ON person.person_id = person_meeting.person_id
-> WHERE person.person_id IN (SELECT person_id
-> FROM person_meeting
-> WHERE meeting_id IN ((SELECT meeting_id
-> FROM meeting
-> WHERE meeting_id NOT IN (SELECT meeting_id
-> FROM meeting
-> WHERE meeting_start >'2016-12-25 00:00:00')));

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ri ght syntax to use near '' at line 11

2
  • At a guess I'd say the error's on line 2 with the bracket between JOIN and MEETING. Not a MySQL userm though. Commented Jun 24, 2017 at 9:56
  • Rewrite the query to avoid using IN ( SELECT ... ) . Usually such can be converted into JOINs.
    – Rick James
    Commented Jul 4, 2017 at 17:35

1 Answer 1

1

Your SQL query has unbalanced parenthesis. You open 5 parenthesis, you close 4. This would solve it:

SELECT 
    person.first_name, person.last_name, meeting.meeting_id, meeting.meeting_start, meeting.meeting_end
FROM 
    person 
    INNER JOIN 
    (
        meeting
        INNER JOIN person_meeting 
             ON meeting.meeting_id = person_meeting.meeting_id
    )
    ON person.person_id = person_meeting.person_id
WHERE 
    person.person_id IN 
    (
        SELECT 
            person_id
        FROM 
            person_meeting
        WHERE 
            meeting_id IN 
            (
                (SELECT 
                     meeting_id
                 FROM 
                      meeting
                 WHERE 
                      meeting_id NOT IN 
                      (
                          SELECT 
                              meeting_id
                          FROM 
                              meeting
                          WHERE 
                               meeting_start > '2016-12-25 00:00:00'
                      )
                 )
           )
      ) ;

Plus: your query is more complicated that it needs be. You seem to look for all meetings attended by people who attended meetings NOT starting later than 20161225. This can be achieved with one less level of subquery, plus some simplification at the top JOINs:

SELECT 
    person.first_name, person.last_name, meeting.meeting_id, meeting.meeting_start, meeting.meeting_end
FROM 
    person 
    JOIN person_meeting ON person_meeting.meeting_id = person.person_id
    JOIN meeting ON meeting.meeting_id = person_meeting.meeting_id
WHERE     
    person.person_id IN 
    (SELECT  /* s2: Persons NOT having attended meetings NOT starting {1} */
        person_id
    FROM 
        person_meeting
    WHERE 
        meeting_id IN 
        (SELECT /* s1: Meetings NOT starting later than 20161225 {1} */
            meeting_id
        FROM 
            meeting
        WHERE 
            meeting_start <= /* reversed! */  '2016-12-25 00:00:00'
        )
   ) ;

Check it all at dbfiddle here

Not the answer you're looking for? Browse other questions tagged or ask your own question.