select m1.id, m1.status, at.view_data, at.view_graph, ta.tag_string
from
access_tbl at, image_campaign_tbl m1
RIGHT JOIN
(select
GROUP_CONCAT(t.name) as tag_string , c.image_campaign_id
from campaign_tags_tbl c,tag_tbl t
where c.tag_id=t.id
$tag_q
group by c.image_campaign_id
) as ta
ON ta.image_campaign_id=m1.id
where
m1.client_id =$client_id
and m1.client_id = at.client_id
$prev_filter
limit $start,$end;
错误讯息:
LOGS中的:DBD :: mysql :: db selectall_arrayref失败:/home/sakthi/rtads/Project/pm/Image/UI.pm第2536行的'where子句'中的未知列't.name'。**
在Perl模块中,我将$ tag_q的相同值传递给$ prev_filter,以根据下一页中的TAGS值获取过滤器的分页
if ( $prev_filter eq '' ) {
$prev_filter =
$search_clist_q . ' '
. $tag_q . ' '
}
从错误消息msg中,我得到了我正在做的错误。由于我正在尝试访问主查询中的子查询表,因此发生此错误。
所以我想知道如何访问子查询外的tag_string(或)t.name。
答案 0 :(得分:1)
首先,我建议你不要使用旧学校语法来建立联合(FROM table1, table2,... WHERE table1.column1 = table2.column2 AND ...
)。
这是一个似乎返回您正在寻找的内容的查询:
SELECT IC.id
,IC.status
,A.view_data
,A.view_graph
,TA.tag_string
FROM access_tbl A
INNER JOIN image_campaign_tbl IC ON IC.client_id = A.client_id
AND IC.client_id = $client_id
RIGHT JOIN (SELECT CT.image_campaign_id
,GROUP_CONCAT(T.name) AS [tag_string]
FROM campaign_tags_tbl CT
INNER JOIN tag_tbl T ON T.id = CT.tag_id
GROUP BY CT.image_campaign_id) TA ON TA.image_campaign_id = IC.id
WHERE <Your filters here>
LIMIT $start, $end
希望这会对你有所帮助。