我收到错误“未知表”错误?

时间:2011-03-17 17:05:15

标签: mysql

我已经宣布一个表为“m”仍然是查询给我一个恐怖。这是查询:

select m.id AS id,
       m.product_id AS product_id,
       m.status AS `status`,
       m.pmatch AS pmatch,
       m.p_offset AS p_offset,
       m.smatch AS smatch,
       m.s_offset AS s_offset,
       m.tmatch AS tmatch,
       m.t_offset AS t_offset,
       m.txt1hex AS txt1hex,
       m.txt2hex AS txt2hex,
       m.txt3hex AS txt3hex,
       m.http_host AS http_host,
       m.http_uri AS http_uri,
       m.http_user_agent AS http_user_agent,
       m.http_cookie AS http_cookie,
       m.direction AS direction,
       m.trans AS trans,
       m.conn AS conn,
       m.min_pl_len AS min_pl_len,
       m.max_pl_len AS max_pl_len,
       m.stream_off AS stream_off,
       m.packet_num AS packet_num,
       m.sip AS sip,
       m.sp AS sp,
       m.dip AS dip,
       m.dp AS dp,
       m.stage AS stage,
       m.func_index AS func_index,
       m.usage AS usage,
       m.comments AS comments,
       m.created AS created,
       m.createdby AS createdby,
       m.updated AS updated,
       m.updatedby AS updatedby
from   sp_mip_rule m
where  exists(select 1 AS 1
              from vw_extr_active_socnet_product p
              where ((p.id = sp_mip_rule.product_id) and (sp_mip_rule.status = 1) ))

3 个答案:

答案 0 :(得分:2)

由于您在m子句中将表格别名为FROM我认为您必须在{{1}中将其称为m子句:

WHERE

答案 1 :(得分:2)

&LT 1为卤素;你有一个无与伦比的报价:

m.stream_off` AS stream_off

&LT 2 - ; USAGE是保留字。你需要引用它:

m.usage AS `usage`

&LT 3的密度;如果要将1用作列别名,则需要引用它:

select 1 AS '1'

......或:

select 1 AS `1`

...虽然当然没有必要使用自己的名称对列进行别名。

我建议您在几行中编写SQL代码,并使用带语法高亮的编辑器。这样可以更容易地发现这种错误。

答案 2 :(得分:0)

在WHERE子句中关闭了parens。你已经将m.status=1埋在了存在的内部。我想你想在存在之外进行检查。

...
where m.status = 1 
    and exists(select 1 from vw_extr_active_socnet_product p where p.id = m.product_id)