我在這裏看不到問題,除非我不明白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))'
這裏有什麼語法錯誤?
你有'哪裏\ n哪裏'在那裏。 – Kenney