Every derived table must have its own alias(sql语法错误)

今天在做多表连接查询的时候出现错误:

Every derived table must have its own alias:每一个派生出来的表都必须有一个自己的别名

下面是我执行的错误的sql语句:

select *from port as p join (select *from node as n where n.nodeName="test5" and n.scenario_id = 20) on port.node_id=n.n_id;

小括号括起来的语句是select *from node as n where n.nodeName=”test5” and n.scenario_id = 20,这实际得到的是一个派生表,用这个子sql语句:select *from node as n where n.nodeName=”test5” and n.scenario_id = 20的执行结果当成一张表和前面的node表进行联合查询,错误的原因是:每一个派生出来的表都必须有一个自己的别名,那我给派生表加上别名即可:

修改后的sql:

select *from port as p join (select *from node as n where n.nodeName="test5" and n.scenario_id = 20) as n on p.node_id=n.n_id;

错误解决。

你可能感兴趣的:(mysql,数据库,sql)