Search code examples
mysqlinner-joinalias

Mysql alias the chain of inner joins issue


I have the following query

select *
from
    reservation r,
    (
        assignment a
        INNER JOIN class_ c ON a.class_id = c.uniqueid
        INNER JOIN scheduling_subpart ss ON c.subpart_id = ss.uniqueid
        INNER JOIN instr_offering_config ioc ON ss.config_id = ioc.uniqueid
    ) as io
where
    io.solution_id in (32931842) and
    io = r.offering_id

Note: solution_id is column on the assignment table.

I want the who inner joins in parenthesis to be aliased with io but I'm getting a syntax error:

Check the manual that corresponds to your MySQL server version for the right syntax to use near 'as io where io.solution_id in (32931842) and io = r.offering_id'


Solution

  • It look like you mean to do this:

    select *
    from
    reservation r,
    (
        select * from assignment a ///  You missed the  select * from 
        INNER JOIN class_ c ON a.class_id = c.uniqueid
        INNER JOIN scheduling_subpart ss ON c.subpart_id = ss.uniqueid
        INNER JOIN instr_offering_config ioc ON ss.config_id = ioc.uniqueid
    ) as io
    where
    io.solution_id in (32931842) and
    io = r.offering_id