2016-02-22 36 views
0

我在這裏看不到問題,除非我不明白MySQL中的子查詢。我被給了一個緩慢的查詢,它有很多的LEFT JOIN,所以我試圖將這些JOIN重寫爲子查詢。我一開始是這樣的:關於複雜MySQL子查詢的語法錯誤

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

你有'哪裏\ n哪裏'在那裏。 – Kenney

回答

0

選擇t.title AS標題, (選擇 GROUP_CONCAT通過haha_supplier.display_name ASC分離器(不同haha_supplier.display_name順序 '')AS貢獻者 從haha_supplier其中haha_supplier.supplier_id IN ^ ----

你錯過 where somefield在指定的點...

週一失明......離開這個設置爲個人hairshirt。

+0

咦?另一個地方? –

+1

d'oh ...我的壞。星期一,對不起。那裏有一個地方。我只是失明。但是,查詢中的其他位置確實有太多'where'。 –

+0

謝謝你。錯誤消息似乎是誤導性的。它指向錯誤的路線。 – lorm