7

如何通过设置别名来纠正此错误?错误:#1248 - 每个派生表都必须有自己的别名

SELECT 
    entry_id,
    author_id,
    title,
    status
FROM exp_channel_titles

LEFT JOIN
(SELECT
    entry_id, 
    field_id_14,
    field_id_15,
    field_id_25,
    field_id_27, 
    field_id_28, 
    field_id_29, 
    field_id_30,
    field_id_31,
    field_id_32,
    field_id_33,
    field_id_34,
    field_id_35
FROM exp_channel_data
WHERE entry_id = exp_channel_titles.entry_id)

LEFT JOIN
(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id)

WHERE title LIKE %Member% 
AND status = 'complete'
4

2 回答 2

20

好吧,正如错误所说,您必须命名每个派生表。例如

(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id)

是派生表。添加这样的名称:

(SELECT   
    member_id,
    email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id) tempTableNameGoesHere

(我想我确定括号和名称之间不需要一个as,但我想你可以尝试一下,或者从这里查找它;))

您的后续问题(我们要这样做多久?:))

 WHERE title LIKE %Member% 

应该

WHERE title LIKE '%Member%'
于 2012-05-08T08:48:26.937 回答
1
SELECT 
    ect.entry_id,
    ect.author_id,
    ect.title,
    ect.status
FROM exp_channel_titles as ect

LEFT JOIN
(SELECT
    entry_id, 
    field_id_14,
    field_id_15,
    field_id_25,
    field_id_27, 
    field_id_28, 
    field_id_29, 
    field_id_30,
    field_id_31,
    field_id_32,
    field_id_33,
    field_id_34,
    field_id_35
FROM exp_channel_data) as ecd 
ON ecd.entry_id = ect.entry_id

LEFT JOIN
(SELECT   
    member_id,
    email
FROM exp_members) as exm
ON exm.member_id = ect.author_id

WHERE ect.title LIKE '%Member%' 
AND ect.status = 'complete'
于 2012-05-08T08:59:49.127 回答