mySQL错误:#1248 - 每个派生表必须有自己的别名

时间:2012-05-08 08:45:34

标签: mysql

如何通过设置别名来更正此错误? 错误:#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'

2 个答案:

答案 0 :(得分:19)

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

(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%'

答案 1 :(得分: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'