复杂MySQL子查询的语法错误

时间:2016-02-22 16:47:33

标签: mysql query-optimization

我不能在这里看到问题,除非我不理解MySQL中的子查询。我得到了一个有很多LEFT JOIN的慢查询,所以我试图将这些JOIN重新编写为子查询。我开始是这样的:

  select t.title AS title,
  (select 
    group_concat(distinct haha_supplier.display_name order by haha_supplier.display_name ASC separator ', ') AS contributors
    from haha_supplier where haha_supplier.supplier_id IN
               (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id))
                  AS contributors,
  (select haha_supplier.supplier_id
    from haha_supplier where 
    where haha_supplier.supplier_id IN
               (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id))
                 AS supplier_id,
  (select haha_supplier.group_letter
    from haha_supplier where 
    where haha_supplier.supplier_id IN
               (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id))
                 AS group_letter,
  select 
         group_concat(distinct concat(user.first_name,' ',user.last_name) separator ', ') as marketer
         from user where user.id IN
                (select wawa_suppliers_to_haha_marketing_contacts.user_id from wawa_suppliers_to_haha_marketing_contacts
                where wawa_suppliers_to_haha_marketing_contacts.supplier_id IN
                  (select haha_supplier.supplier_id
                   where haha_supplier.supplier_id IN
                     (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id)))
                         AS marketer,
  select 
         group_concat(distinct concat(user.first_name,' ',user.last_name) separator ', ') AS editor
         from user where user.id IN
                (select wawa_suppliers_to_haha_editors.user_id from wawa_suppliers_to_haha_editors
                where wawa_suppliers_to_haha_editors.supplier_id IN
                  (select haha_supplier.supplier_id
                   where haha_supplier.supplier_id IN
                     (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id)))
                         AS editor,

我得到了:

  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 '       from haha_supplier where haha_supplier.supplier_id IN
                 (select haha_title_to_supplier.supplier_id from haha_title_to_supplier where haha_title_to_supplier.title_id = t.title_id))'

这里的语法错误是什么?

1 个答案:

答案 0 :(得分:0)

<击>     选择t.title AS标题,     (选择       group_concat(distinct haha​​_supplier.display_name order by haha​​_supplier.display_name ASC separator&#39;,&#39;)AS贡献者       来自haha_supplier.supplier_id IN的haha_supplier                                                         ^ ----

<击>

你在指定地点错过了where somefield ......

星期一失明......把它留作个人发型。